在我的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)的頁面右側和其他字段顯示相同的地方。
請幫我...
現在你想創建頁面的圖形視圖?你必須在HTML頁面中實現php代碼,使用CSS給出樣式,這是你想要做的嗎? – Mitro
我正在安排這個連續顯示的自定義字段,我想要地址(街道,城市,州,國家)顯示頁面頂部,以及移動號碼。顯示頁面的右側和其餘字段顯示相同的地方。請幫我這個編碼。 – Sanjib
感謝Alessio的重播,請看我的網站(http://www.opendeals.in/ads/online-jobs-in-india-without-any-investment/),那麼你就明白我的問題了。 – Sanjib