• Resolved zezepedro

    (@zezepedro)


    Scenario:

    • Have categories ‘A’, ‘B’, ‘C’ … ‘Z’ created.
    • In page ‘X’ of my website want to show recent posts from all categories except from category M.

    How can I acomplish this with the available template tags?

    I’ve been arround the function get_posts() but with no success.

    Is there any other way?

    Thanks.

    WP 2.1.2

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    -Have categories ‘A’, ‘B’, ‘C’ … ‘Z’ created.
    -In page ‘X’ of my website want to show recent posts from all categories except from category M.

    First, let’s assume that these categories have numbers. Because you’re going to need the category ID numbers. You could look them up on the Manage->Categories admin page, for example.

    Next, let’s say we’re making a Page and you understand Page Templates.

    Also, while we’re at it, let’s assume you understand The Loop.

    Given those, you could just use query_posts to exclude a category quite easily. Just do query_posts('cat=-3'); to exclude category 3 (for example) right before your Loop, and you’re good to go. You could specify other bits as well.

    Thread Starter zezepedro

    (@zezepedro)

    ALready found the solution -> query_posts()

    Should have looked better in the codex docs for this first.

    My example category ‘M’ has the ID 3. So this is how I’m showing no more than 10 of my latest posts from all categories except M:

    ...
    <?php
    query_posts("cat=-1&showposts=10");
    while (have_posts()) : the_post();
    ?>
    ...
    ?>
    <?php endwhile; ?>

    If by chance you are facing the same situation I was, please read more in this codex doc: (it’s all there)

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

    Cya.

    Thread Starter zezepedro

    (@zezepedro)

    That’s it Otto42!

    Thanks for your help.

    I was writing the “ALready found the solution” post while you posted. Didn’t see your answer before. It would definitely have provided me with the solution.

    I’ll mark this topic as resolved.

    Bye.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘How to show posts from all categories except category “X”’ is closed to new replies.