WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Problem Displaying Recent Posts

[Resolved] Problem Displaying Recent Posts

  • 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?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Sorry, I know it’s bad form to bump a post but I’m hoping somebody might have an answer…

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

    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 🙂

    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.

    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.

    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.

    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.

    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.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Resolved] Problem Displaying Recent Posts’ is closed to new replies.
Skip to toolbar