WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] How to display last 4 posts of cat 2,3 &7 (for ex.)?

[Resolved] How to display last 4 posts of cat 2,3 &7 (for ex.)?

  • I know how to display last posts for one specific cat, using:

    <?php
    
    // The Query
    query_posts( 'cat=3' );
    
    // The Loop
    while (have_posts()) : the_post(); ?>
    
    <h1><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
    <h2><?php the_time('l j F Y') ?></h2>
    <?php the_content('Lire la suite &raquo;'); ?>
    
    <?php endwhile;
    
    // Reset Query
    wp_reset_query();
    
    ?>

    But I did not find the way to display last x (4 for ex.) posts from different categories (for ex cat 2, 3 & 7). I want those posts to be displayed from the most recent one to the oldest one (of the 4).

    I read this page but a bit messy for the beginner I am:
    http://codex.wordpress.org/Template_Tags/query_posts

    Any help would be higly appreciated!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Here is now what I have in my query now, it displays 4 last posts from cat3:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('cat=3&posts_per_page=4&paged=' . $paged);

    But still having troubles to display 4 last posts of my website, post can come from different categories: I want to name them (for ex: cant 2, 3 & 7).

    So I want to display 4 posts in total, from the new one to the oldest one (each of those 4 posts can come from one of those cat).

    Moderator keesiemeijer

    @keesiemeijer

    For all the parameters used by query_posts read this: http://codex.wordpress.org/Function_Reference/WP_Query

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('cat=2,3,7&posts_per_page=4&paged=' . $paged);

    works just great!
    Thanks keesiemer!!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] How to display last 4 posts of cat 2,3 &7 (for ex.)?’ is closed to new replies.