Display recent posts based on their category in Wordpress

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 12:54:33

问题


I use a template that generates thumbnails on the content.php page like so:

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

I am just starting with Wordpress and php and I want to add a parameter to this so only posts with category 'showcase' i.e. will show up. Anyone an idea?


回答1:


You can use in_category() function to test that post belongs to it.

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

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



来源:https://stackoverflow.com/questions/13587958/display-recent-posts-based-on-their-category-in-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!