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

请问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的数组


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


single_cat_title()


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; ?>

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

貌似还是空的呢


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

【热门文章】
【热门文章】