我试图在单个页面上输出类别及其帖子,但出于某种原因,所有类别中的帖子都在每个类别中重复,我做错了什么这里的代码:
<?php
#Template Name: food
get_header();
?>
<?php
$taxonomy = \'category\';
$param_type = \'category__in\';
$term_args = array(
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'exclude\' => 1
);
$terms = get_terms($taxonomy, $term_args);
?>
<div class="row">
<?php if($terms) : ?>
<?php $counter = 0; foreach($terms as $term) : $counter++; ?>
<?php
$args = array(
\'$param_type\' => array($term->term_id),
\'post_type\' => \'food\',
\'post_status\' => \'publish\',
\'posts_per_page\' => -1
);
$my_query = null;
$my_query = new Wp_Query($args);
?>
<?php if($my_query->have_posts()) : ?>
<?php if($counter == 2): ?>
<ul class="menu-list sixcol last">
<?php $counter = 0; else: ?>
<ul class="menu-list sixcol">
<?php endif; ?>
<h3><?php echo $term->name; ?></h3>
<?php
while($my_query->have_posts()): $my_query->the_post();
$post_meta_data = get_post_custom($post->ID);
$price = $post_meta_data[\'fangshsu_price\'][0];
?>
<li>
<strong><?php the_title(); ?></strong>
<i><?php if($price) {echo \'£\' . $price;} ?></i>
<?php the_content();?>
</li>
<?php wp_reset_query(); endwhile; ?>
</ul>
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
</div>
<?php get_footer(); ?>
最合适的回答,由SO网友:Sagive 整理而成
你在第24行调用一个奇怪的参数,我不明白。。。您是否从其他地方复制粘贴此函数?
无论如何
change line 24 from:
\'$param_type\' => array($term->term_id),
To this:
\'cat\' => array($term->term_id),
祝你好运,不要忘记阅读@toscho评论,以了解未来的问题。