当前我自定义了一个post_type.对于类型是post的文章get_the_category();可以很轻松获取当前文章的分类.但是对于自定义post_type的文章就不起效了.请问自定义post_type的文章如何获取分类?
global $post;
$categories = get_the_category($post->ID);
var_dump($categories);
也无效.显示长度为0的数组
当前我自定义了一个post_type.对于类型是post的文章get_the_category();可以很轻松获取当前文章的分类.但是对于自定义post_type的文章就不起效了.请问自定义post_type的文章如何获取分类?
global $post;
$categories = get_the_category($post->ID);
var_dump($categories);
也无效.显示长度为0的数组
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
详细的在这里 http://www.binarymoon.co.uk/2010/03/5-wordpress-queryposts-tips/ (需要梯子)
1 回答4k 阅读✓ 已解决
3 回答1.8k 阅读✓ 已解决
2 回答2.2k 阅读✓ 已解决
1 回答1.4k 阅读✓ 已解决
2 回答2.2k 阅读
1 回答1.4k 阅读
1 回答569 阅读✓ 已解决
你要找的是不是query_posts()这个函数