admin管理员组文章数量:1406177
I have registered a custom post type "Projects" and also registered a custom taxonomy for that Post Type called "Project Categories". On my home page I have a div in which I would like to list all projects and terms fro the "Project Categories" taxonomy. Currently, I am only able to get the lists of the terms. Can someone tell me why I am unable to get the terms to display. Currently, I have:
<div class="list-container">
<?php
query_posts( array( 'post_type' => 'projects' ) );
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; wp_reset_query(); ?>
<?php $taxonomy = 'project_categories';
$tax_terms = get_terms($taxonomy);
?>
<?php foreach ($tax_terms as $cat): ?>
<li><?php $cat; ?></li>
<?php endforeach; ?>
</div><!--end list-container-->
Another question I have is, is it better to include the taxonomies inside or outside of the query_posts loop?
I have registered a custom post type "Projects" and also registered a custom taxonomy for that Post Type called "Project Categories". On my home page I have a div in which I would like to list all projects and terms fro the "Project Categories" taxonomy. Currently, I am only able to get the lists of the terms. Can someone tell me why I am unable to get the terms to display. Currently, I have:
<div class="list-container">
<?php
query_posts( array( 'post_type' => 'projects' ) );
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; endif; wp_reset_query(); ?>
<?php $taxonomy = 'project_categories';
$tax_terms = get_terms($taxonomy);
?>
<?php foreach ($tax_terms as $cat): ?>
<li><?php $cat; ?></li>
<?php endforeach; ?>
</div><!--end list-container-->
Another question I have is, is it better to include the taxonomies inside or outside of the query_posts loop?
Share Improve this question asked Apr 8, 2016 at 18:58 JordanBarberJordanBarber 1435 bronze badges1 Answer
Reset to default 1You'e not echoing out $cat
in your foreach loop in the code you provided.
Change : <li><?php $cat; ?></li>
to <li><?php echo $cat; ?></li>
Edit:
get_terms()
returns an array of objects. So if you want to display the name of the term in your foreach loop it would be:
<li><?php echo $cat->name; ?></li>
本文标签: List terms from Custom Taxonomy
版权声明:本文标题:List terms from Custom Taxonomy 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744969201a2635133.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论