gpt4 book ai didi

php - wordpress 在 wordpress 循环中获取自定义帖子类型的类别名称?

转载 作者:可可西里 更新时间:2023-11-01 00:30:54 24 4
gpt4 key购买 nike

我想在查询帖子循环中获取自定义帖子类型的类别名称。

这是我的代码:

query_posts(array('post_type'=>'portfolio','posts_per_page'=>4, 'orderby' => 'ID', 'order' => 'DESC' ));

while ( have_posts() ) : the_post();

<li>
<div class="foli_img"> <a href="<?php echo get_permalink();?>"> <span class="next"> </span> </a> <?php the_post_thumbnail();?> </div>
<h3 class="style"><?php the_title();?></h3>
<?php the_content();?>
<h4><a href="#">I want the category name here</a></h4>
</li>
<?php endwhile;?>

最佳答案

试试这个

<?php

while ( have_posts() ) :
the_post();?>
<li>
<div class="foli_img">
<a href="<?php echo get_permalink();?>">
<span class="next"> </span>
</a>
<?php the_post_thumbnail();?>
</div>
<h3 class="style"><?php the_title();?></h3>
<?php the_content();?>
<h4><a href="#">
<?php
$category = get_the_category( $post->ID );
echo $category[0]->cat_name;?></a></h4>
</li>
<?php
endwhile;?>

尝试通过条款:

$terms = get_the_terms($post->ID, 'Enter_your_taxonomy_here' );
if ($terms && ! is_wp_error($terms)) :
$tslugs_arr = array();
foreach ($terms as $term) {
$tslugs_arr[] = $term->slug;
}
$terms_slug_str = join( " ", $tslugs_arr);
endif;
echo $terms_slug_str;

关于php - wordpress 在 wordpress 循环中获取自定义帖子类型的类别名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32048744/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com