微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php-根据WordPress中的类别显示最近的帖子

我使用的模板在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 -->

我只是从wordpressPHP开始,我想为此添加一个参数,因此只有类别为’showcase’的帖子才会显示.有人知道吗?

解决方法:

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

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

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐