请问wordpress中如何获取自定义post_type的分类

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

阅读 9.7k
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(); ?>

 <div 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>

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

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

 <?php endwhile; else: ?>
 <p>Sorry, no posts matched your criteria.</p>
 <?php endif; ?>
新手上路,请多包涵

single_cat_title()

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

貌似还是空的呢

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题