我试图在存档页上显示特定帖子类型的术语。我不明白如何“呼应”术语名称。这是我的代码:
<?php $terms = get_terms("event_cat"); ?>
<?php while (have_posts()) : the_post(); ?>
print term->name here
<?php endwhile; ?>
我试图在存档页上显示特定帖子类型的术语。我不明白如何“呼应”术语名称。这是我的代码:
<?php $terms = get_terms("event_cat"); ?>
<?php while (have_posts()) : the_post(); ?>
print term->name here
<?php endwhile; ?>
get_terms()
通常检索术语,它不会连接到当前的post in循环。
您需要的是一个模板标记,用于检索文章的术语。例如the_terms()
:
while (have_posts()) : the_post();
the_terms( get_the_ID(), \'event_cat\' );
endwhile;
有相当多的函数处理术语,这取决于您想对数据做什么。我使用以下代码将帖子ID存储到数组中:<?php $args = array( \'post_type\' => \'product\', \'post_status\' => \'publish\', \'ignore_sticky_posts\' => 1, \'posts_per_page\' => 5, \'orderby\' =