[resolved] Problem Displaying Recent Posts (9 posts)

  1. tauquil
    Posted 10 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
    Posted 10 years ago #

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

  3. Phunky
    Posted 10 years ago #

    #ignore this cat
    } else {
    place your WP code to print the posts here

  4. moshu
    Posted 10 years ago #

    I think you'll find an answer in this thread:
    (you could just search for query_posts offset :)

  5. tauquil
    Posted 10 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
    Posted 10 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
    Posted 10 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
    Posted 10 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
    Posted 10 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