【发布时间】:2014-03-26 21:21:45
【问题描述】:
在我的 wordpress 主题中,我正在创建一些自定义字段,例如
cp_street、cp_city、cp_mobile_no、cp_company_name
等等。显示在single_ad_listing.php页面,代码为
cp_get_ad_details( $post->ID, $cat_id );
和theme-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赋予样式,这是你想要的吗?
-
我正在安排这个连续显示的自定义字段,我想在页面顶部显示地址(街道、城市、州、国家)和手机号码。显示页面右侧和字段的其余部分显示相同的位置。请帮我做这个编码。
-
感谢 Alessio 重播,请查看我的网站 (opendeals.in/ads/online-jobs-in-india-without-any-investment),然后您就明白我的问题了。
标签: php wordpress custom-fields