• Hi,

    I’m looking for a way to list (with php) the last recent post of a category.
    I know its possible to list the most recent posts but that’s nog what i’m looking for as my design asks for listing it in a specific way without a loop.

    So i’m looking for the code to list apart:
    – the most recent post of category x
    – the second most recent post of category x
    – the third most recent post of category x
    – the fourth most recent post of category x

    To give a live example of the page: http://www.nono.be/home
    It’s the yellow/green blocks that i’m talking about.

    If there is any one who can help me out that would be really cool.
    Thanks for the quick response.

Viewing 6 replies - 1 through 6 (of 6 total)
  • <?php
    $cat_name = "X";
    $catID = get_cat_ID($cat_name);
    query_posts('showposts=4&cat='.$catID);
    while(have_posts()): the_post();
    /////////REST PART YOU WILL DO////////
    endwhile;
    ?>

    C
    http://www.marketingadsandseo.com

    Thread Starter filipvanreeth

    (@filipvanreeth)

    Hi,

    Thanks for the quick reponse.

    I do get error when i add this to the place. I guess there is something wrong with the quotes?

    <?php
    $cat_name = “X”;
    $catID = get_cat_ID($cat_name);
    query_posts(‘showposts=4&cat=’.$catID);
    while(have_posts()): the_post();
    <div class=”square-info-2-1″>
    <div class=”v-outer”>
    <div class=”v-middle”>
    <div class=”v-inner”>
    <h2><?php the_title(); ?></h2>
    <p><?php $key=”Label”; echo get_post_meta($post->ID, $key, true); ?></p>
    </div>
    </div>
    </div>
    </div>

    <div class=”square-img-2-1″>
    ” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_post_thumbnail(); ?>
    </div>
    endwhile;
    ?>

    <?php
    $cat_name = "X";
    $catID = get_cat_ID($cat_name);
    query_posts('showposts=4&cat='.$catID);
    while(have_posts()): the_post();
    ?>
    <div class="square-info-2-1">
    <div class="v-outer">
    <div class="v-middle">
    <div class="v-inner">
    <h2><?php the_title(); ?></h2>
    <p><?php $key="Label"; echo get_post_meta($post->ID, $key, true); ?></p>
    </div>
    </div>
    </div>
    </div>
    
    <?php
    endwhile;
    ?>

    Look my code and then change as your choice.

    Thread Starter filipvanreeth

    (@filipvanreeth)

    Hi,

    I think we are on the wrong lane. Your code displays the 4 most recent posts of that category. What we are trying to achieve is just to display the fourth (or other number) most recent post of that category without showing any other most recent post.

    use sql query, $wpdb object, get_results function, limit etc for that

    define your $cat_id with whatever method you want;

    get_posts('numberposts=1&category='.$cat_id.'&offset=3')

    control your position with the offset parameter

    http://codex.wordpress.org/Template_Tags/get_posts

    the first example there is close to what you could try.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Show first, second, third or fourth most recent post of a category’ is closed to new replies.