[resolved] Exclude Category from Recent Posts in sidebar (7 posts)

  1. Stahn
    Posted 10 years ago #

    This is my code to get the latest posts (6 is not a category, is how many posts are displayed):

    <?php get_archives('postbypost','6','html'); ?>

    I tried, before that:

    <?php if (in_category('1')) continue; ?>

    And also this: http://codex.wordpress.org/Template_Tags/query_posts#Excluding_Multiple_Categories

    No luck with any.

    This is because I don't want the asides titles showing there.

  2. Stahn
    Posted 10 years ago #

    Bump. I need this ASAP, I can't put my site online because of this. Tried lots of stuff but still can't do it.

  3. MichaelH
    Posted 10 years ago #

    Looks like the SideBlog plugin might allow you to specify the categories that get published as asides.


  4. Stahn
    Posted 10 years ago #

    Read again my first post =P

    (Recent Posts isn't Sideblog)

  5. Stahn
    Posted 10 years ago #

    Ok, found an approximation:

    <?php $temp_query = $wp_query; // save original loop ?>
    <?php query_posts("cat=-19&showposts=10"); // exclude the asides category and get the latest 10 posts ?>
    <?php while (have_posts()) : the_post(); ?>

    <li><a>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
    <?php endwhile; ?>
    <?php $wp_query = $temp_query; // revert to original loop ?>

    This should work, but gives me this error:

    WordPress database error: [Not unique table/alias: 'wp_post2cat']
    SELECT DISTINCT * FROM wp_posts LEFT JOIN wp_post2cat ON (wp_posts.ID = wp_post2cat.post_id) LEFT JOIN wp_post2cat ON (wp_posts.ID = wp_post2cat.post_id) WHERE 1=1 AND 0=1 AND (category_id != 19) AND post_date_gmt <= '2006-05-12 13:54:59' AND (post_status = "publish" OR post_author = 1 AND post_status != 'draft' AND post_status != 'static') AND post_status != "attachment" AND category_id != 19 GROUP BY wp_posts.ID ORDER BY post_date DESC LIMIT 0, 10

    If I remove the '-' of '-19' the first code thing works, but of course I don't want to show that category, and I know that I cannot include more than one category when query_posts is used.

  6. Stahn
    Posted 10 years ago #

    OMG I did broke the layout =P

    Customizable Post Listings to the rescue! I could do this after long hours with one of my favorite plugins =)


    The winner:

    <?php c2c_get_recent_posts(7,"
    ", "1, 12, 13, 14, 15, 16, 17, 18"); ?>

    As you see, I must now add the categories manually, which is a damn hassle, but at least works.

    It would have been SO MUCH easier if get_archives had an option to exclude categories...

  7. rembem
    Posted 10 years ago #

    I posted a reply on this subject in another thread.

    This works for me. I use it for exactly the same purpose: not showing my Asides titles in my Recent posts lists.

    The code looks like Stahns code above, but is not exactly the same.

Topic Closed

This topic has been closed to new replies.

About this Topic