【发布时间】:2015-10-16 04:02:06
【问题描述】:
我有一个名为“电子”的自定义帖子类型,其分类类别称为“计算机、手机、笔记本电脑......等等”
在 taxonomy.php 模板中,我设法使用此代码获取了分类名称、slug 和 id。
<?php
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
echo $term->name; // will show the name
echo $term->slug; // will show the slug
echo $term->term_id; // will show the id
?>
所以如果我在计算机分类页面中,我会得到'Computers computers 11'
无论是 pf 每次生成的值,我如何根据我所在的“分类页面”生成帖子。例如。计算机分类页面中带有“计算机”标签的帖子,电话分类页面中带有手机标签的帖子......等等。
类似这样的东西,但对于分类法......
<?php
$catquery = new WP_Query( 'cat=3' );
while($catquery->have_posts()) : $catquery->the_post();
?>
<ul>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
<ul><li><?php the_content(); ?></li>
</ul>
</li>
</ul>
<?php endwhile; ?>
【问题讨论】:
-
只需将自定义查询替换为默认循环,该循环将显示作为主查询返回的正确帖子
标签: php wordpress custom-taxonomy