WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Problem Displaying Recent Posts (9 posts)

  1. tauquil
    Member
    Posted 8 years ago #

    I hope somebody with muchos php knowledge will be able to help me. What I'd like to be able to do is show one main post, followed by a list of the five most recent posts (NOT including the main post) AND exclude a certain category from those links.

    From studying the codex I've been able to use "$posts = get_posts" and set an offset value to display the five most recent posts, minus the already displayed main post but haven't figured out how to exclude a category.

    I've tried using "query_posts", which allows me to exclude a category but I can't figure out how to offset the most recent posts by 1.

    Am I just missing something obvious?

  2. tauquil
    Member
    Posted 8 years ago #

    Sorry, I know it's bad form to bump a post but I'm hoping somebody might have an answer...

  3. Phunky
    Member
    Posted 8 years ago #

    <php
    if(is_category($id)){
    #ignore this cat
    } else {
    place your WP code to print the posts here
    }
    ?>

  4. moshu
    Member
    Posted 8 years ago #

    I think you'll find an answer in this thread:
    http://wordpress.org/support/topic/28203#post-193667
    (you could just search for query_posts offset :)

  5. tauquil
    Member
    Posted 8 years ago #

    Thanks moshu, I'm reading the thread but can't quite seem to make it work for me.

    Here's the code I'm using:

    <?php $temp_query = $wp_query; ?><br />
    <?php query_posts('cat=-1&showposts=5'); ?><br />
    <?php while (have_posts()) : the_post(); ?><br />
    <a>"><?php the_title(); ?></a><br />
    <?php the_excerpt(); ?><br />
    <?php endwhile; ?><br />
    <?php $wp_query = $temp_query; ?>

    What would be the changes I would need to make? Thanks for any help.

  6. moshu
    Member
    Posted 8 years ago #

    Sorry, I don't know. I am not a coder - that's why I had to ask. But I am very good at copying <grin>, so I just copied the code from there and, of course, added the necessary template tags, and it worked.

  7. tauquil
    Member
    Posted 8 years ago #

    I couldn't quite paste the code right above, I'll keep plugging away - no doubt it's an error on my part.

    Thanks for the heads up.

  8. moshu
    Member
    Posted 8 years ago #

    1. For posting small code snippets use the "backticks" (usually on the same key where ~ [tilde] is on your keyboard) - see the instructions below the posting area here
    2. For long code use http://pastebin.com and post back with the URI.

  9. tauquil
    Member
    Posted 8 years ago #

    Oooh, I think it's working!

    I didn't merge the two snippets of code together properly...I told you it would be user error! Thanks for the help, and to Kafkaesqui for the advice on the other thread.

Topic Closed

This topic has been closed to new replies.

About this Topic