繁体   English   中英

在Wordpress中的帖子旁边显示自定义帖子类型分类法术语

[英]Showing Custom Post Type Taxonomy Terms Next to Post in Wordpress

我有一个自定义后类型,称为recipe和自定义分类称为cuisinerecipe_type

我想在页面上显示10个食谱的列表及其所属分类法的相关术语:

我有以下代码,显示了配方,但没有该分类法术语:

<?php 
query_posts(array( 
    'post_type' => 'recipe',

    'showposts' => 10
) );  
?>
<?php while (have_posts()) : the_post(); ?>
    <li>
    <?php the_title(); ?> 
    <?php $terms = wp_get_post_terms( $query->post->ID, array( 'cuisine', 'recipe_type' ) ); ?>

    <?php foreach ( $terms as $term ) : ?>
    <p><?php echo $term->taxonomy; ?>: <?php echo $term->name; ?></p>
    <?php endforeach; ?>

    </li>


<?php endwhile;?>

以下代码可以显示与自定义帖子类型相关的分类术语

<?php 
query_posts(array( 
'post_type' => 'recipe',

'showposts' => 10
) );  
?>

<?php while (have_posts()) : the_post(); ?>
<li>
<?php the_title(); ?> 
<?php $terms = get_the_terms( $post->ID , 'recipe_type' ); ?>

<?php foreach ( $terms as $term ) : ?>
<p><?php echo $term->taxonomy; ?>: <?php echo $term->name; ?></p>
<?php endforeach; ?>

</li>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM