根据Wordpress中的类别显示最近的帖子

时间:2012-11-27 15:51:42

标签: php wordpress filter categories posts

我使用的模板在content.php页面上生成缩略图,如下所示:

<article <?php post_class('single-entry clearfix'); ?>>  
<?php
// Test if post has a featured image
if( has_post_thumbnail() ) { 
    // Get resize and show featured image : refer to functions/img_defaults.php for default values
    $wpex_entry_img = aq_resize( wp_get_attachment_url( get_post_thumbnail_id(), 'full' ),  wpex_img( 'blog_entry_width' ), wpex_img( 'blog_entry_height' ), wpex_img( 'blog_entry_crop' ) );
?>
    <div class="single-entry-thumbnail">
        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><img src="<?php echo $wpex_entry_img; ?>" alt="<?php echo the_title(); ?>" /></a>
    </div><!-- /single-entry-thumbnail -->
<?php } ?>
<div class="entry-text clearfix">
    <header>
        <h3><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
    </header>
</div><!-- /entry-text -->

我刚刚开始使用Wordpress和php,我想为此添加一个参数,因此只有“showcase”类别的帖子会显示出来。有人有想法吗?

1 个答案:

答案 0 :(得分:0)

您可以使用in_category()函数来测试该帖子属于它。

if ( in_category( 'showcase' ) ) {
    ...
}

in_category()docs - http://codex.wordpress.org/Function_Reference/in_category