2014-03-26 57 views
1

在我的wordpress主题,我创建像WordPress的自定义字段设置

cp_street,cp_city,cp_mobile_no,cp_company_name

等等一些自定义字段。这是显示在single_ad_listing.php页面和代码是

cp_get_ad_details($post->ID, $cat_id); 

和主题function.php页面代码是

// display all the custom fields on the single ad page, by default they are placed in the list area 
if (! function_exists('cp_get_ad_details')) { 
    function cp_get_ad_details($post_id, $category_id, $location = 'list') { 
     global $wpdb; 

     // see if there's a custom form first based on category id. 
     $form_id = cp_get_form_id($category_id); 

     $post = get_post($post_id); 
     if (! $post) 
      return; 

     // if there's no form id it must mean the default form is being used 
     if (! $form_id) { 

      // get all the custom field labels so we can match the field_name up against the post_meta keys 
      $sql = "SELECT field_label, field_name, field_type FROM $wpdb->cp_ad_fields"; 

     } else { 

      // now we should have the formid so show the form layout based on the category selected 
      $sql = $wpdb->prepare("SELECT f.field_label, f.field_name, f.field_type, m.field_pos FROM $wpdb->cp_ad_fields f " 
       . "INNER JOIN $wpdb->cp_ad_meta m ON f.field_id = m.field_id WHERE m.form_id = %s ORDER BY m.field_pos ASC", $form_id); 

     } 

     $results = $wpdb->get_results($sql); 

     if (! $results) { 
      _e('No ad details found.', APP_TD); 
      return; 
     } 

     // allows to hook before ad details 
     cp_action_before_ad_details($results, $post, $location); 

     foreach ($results as $result) { 

      // external plugins can modify or disable field 
      $result = apply_filters('cp_ad_details_field', $result, $post, $location); 
      if (! $result) 
       continue; 

      $disallow_fields = array('cp_price', 'cp_currency'); 
      if (in_array($result->field_name, $disallow_fields)) 
       continue; 

      $post_meta_val = get_post_meta($post->ID, $result->field_name, true); 
      if (empty($post_meta_val)) 
       continue; 

      if ($location == 'list') { 
       if ($result->field_type == 'text area') 
        continue; 

       if ($result->field_type == 'checkbox') { 
        $post_meta_val = get_post_meta($post->ID, $result->field_name, false); 
        $post_meta_val = implode(", ", $post_meta_val); 
       } 

       $args = array('value' => $post_meta_val, 'label' => $result->field_label, 'id' => $result->field_name, 'class' => ''); 
       $args = apply_filters('cp_ad_details_' . $result->field_name, $args, $result, $post, $location); 

       if ($args) 
        echo '<li id="' . $args['id'] . '" class="' . $args['class'] . '"><span>' . esc_html(translate($args['label'], APP_TD)) . ':</span> ' . appthemes_make_clickable($args['value']) . '</li>'; 

      } elseif ($location == 'content') { 
       if ($result->field_type != 'text area') 
        continue; 

       $args = array('value' => $post_meta_val, 'label' => $result->field_label, 'id' => $result->field_name, 'class' => 'custom-text-area dotted'); 
       $args = apply_filters('cp_ad_details_' . $result->field_name, $args, $result, $post, $location); 

       if ($args) 
        echo '<div id="' . $args['id'] . '" class="' . $args['class'] . '"><h3>' . esc_html(translate($args['label'], APP_TD)) . '</h3> ' . appthemes_make_clickable($args['value']) . '</div>'; 

      } 
     } 

所有字段显示顺序,但我想喜欢的地址cp_street, cp_city顶部的页面和手机号码(cp_mobile_no)的页面右侧和其他字段显示相同的地方。

请帮我...

+0

现在你想创建页面的图形视图?你必须在HTML页面中实现php代码,使用CSS给出样式,这是你想要做的吗? – Mitro

+0

我正在安排这个连续显示的自定义字段,我想要地址(街道,城市,州,国家)显示页面顶部,以及移动号码。显示页面的右侧和其余字段显示相同的地方。请帮我这个编码。 – Sanjib

+0

感谢Alessio的重播,请看我的网站(http://www.opendeals.in/ads/online-jobs-in-india-without-any-investment/),那么你就明白我的问题了。 – Sanjib

回答

0

在本教程中,我们将着眼于先进的自定义字段插件如何可以被用来创建一个专业的主页。

i hope this like use full.. here simple code..

+0

我已经创建自定义字段,并正常工作。我正在安排这个连续显示的自定义字段,我想要地址(街道,城市,州,国家)显示页面顶部,以及移动号码。显示页面的右侧和其余字段显示相同的地方。请帮我这个编码。 – Sanjib