php - 请问wordpress中如何获取自定义post_type的分类
天蓬老师
天蓬老师 2017-04-10 14:25:28
[PHP讨论组]

当前我自定义了一个post_type.对于类型是post的文章get_the_category();可以很轻松获取当前文章的分类.但是对于自定义post_type的文章就不起效了.请问自定义post_type的文章如何获取分类?
global $post;
$categories = get_the_category($post->ID);
var_dump($categories);
也无效.显示长度为0的数组

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

全部回复(5)
阿神

你要找的是不是query_posts()这个函数

迷茫

query_posts() 要指定 post_type

http://wordpress.stackexchange.com/qu...

<?php query_posts(array( 'post_type' => 'Portfolio' )); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

 <p class="post">

 <!-- Display the Title as a link to the Post's permalink. -->
 <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>

 <!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->
 <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>

  <p class="entry">
    <?php the_content(); ?>
  </p>

  <p class="postmetadata">Posted in <?php the_category(', '); ?></p>
 </p> <!-- closes the first p box -->

 <?php endwhile; else: ?>
 <p>Sorry, no posts matched your criteria.</p>
 <?php endif; ?>
黄舟

建议用query_posts
详细的在这里 http://www.binarymoon.co.uk/2010/03/5-wordpress-queryposts-tips/ (需要梯子)

天蓬老师

single_cat_title()

伊谢尔伦

正确答案是什么?
我用query_posts() 要指定 post_type

貌似还是空的呢

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号