繁体   English   中英

在Wordpress中根据类别显示最新帖子

[英]Display recent posts based on their category in 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 -->

我只是从Wordpress和php开始,我想为此添加一个参数,因此只有类别为“ showcase”的帖子才会显示。 有人知道吗?

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM