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

  1. thomas514
    Posted 4 years ago #

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

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

    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:

    Any help would be higly appreciated!

  2. thomas514
    Posted 4 years ago #

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

  3. keesiemeijer
    Posted 4 years ago #

    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);
  4. thomas514
    Posted 4 years ago #

    works just great!
    Thanks keesiemer!!

Topic Closed

This topic has been closed to new replies.

About this Topic