我有一个高级自定义字段组,在组内部和组内部是一些字段和一个用户选择类别的选择字段。我想根据选择的类别输出到页面上。
以下是我尝试的代码:
<?php
$limit = get_option('posts_per_page');
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts('post_type=Specialist_post&showposts=' . $limit . '&paged=' . $paged);
$wp_query->is_archive = true; $wp_query->is_home = false;
if(have_posts()) :
while(have_posts()) :
the_post();
if(get_field('category') == "1402")
{ ?>
<div class="row wheelsspecial">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<h3><?php the_field('company_name'); ?></h3>
<p><?php the_field('brief_description'); ?></p>
<p><?php the_field('contact_number'); ?></p>
<a href=""><?php the_field('website_address'); ?></a><br />
<a href="mailto:"><?php the_field('email'); ?></a>
<?php } else if (get_field('category') == "1403") {?>
<div class="row tuningspecial">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<h3><?php the_field('company_name'); ?></h3>
<p><?php the_field('brief_description'); ?></p>
<p><?php the_field('contact_number'); ?></p>
<a href=""><?php the_field('website_address'); ?></a><br />
<a href="mailto:"><?php the_field('email'); ?></a>
<?php } ?>
<?php
endwhile;
else:
?>
Oops, there are no posts.
<?php
endif;
?>
现在没有输出任何内容,如果我回显字段类别它返回1403,所以我认为它至少输出其他如果,也许这整个代码设计是错误的。基本上我想根据所选的类别打印不同的div。
答案 0 :(得分:0)
这样做,不是理想的解决方案,现在适用,只需要代码审查
<div class="row wheelsspecial">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<?php
$args = array(
'numberposts' => -1,
'post_type' => 'Specialist_post',
'meta_key' => 'category',
'meta_value' => '1402'
);
$the_query = new WP_Query( $args );
if( $the_query->have_posts() ): ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h3><?php the_field('company_name'); ?></h3>
<p><?php the_field('brief_description'); ?></p>
<p><?php the_field('contact_number'); ?></p>
<a href=""><?php the_field('website_address'); ?></a><br />
<a href="mailto:"><?php the_field('email'); ?></a>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
</div>
</div>
<div class="row tuningspecial">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<?php
$args = array(
'numberposts' => -1,
'post_type' => 'Specialist_post',
'meta_key' => 'category',
'meta_value' => '1403'
);
$the_query = new WP_Query( $args );
if( $the_query->have_posts() ): ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h3><?php the_field('company_name'); ?></h3>
<p><?php the_field('brief_description'); ?></p>
<p><?php the_field('contact_number'); ?></p>
<a href=""><?php the_field('website_address'); ?></a><br />
<a href="mailto:"><?php the_field('email'); ?></a>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
</div>
</div>
全部谢谢