Support » Fixing WordPress » exclluding category from recent posts

  • hi,

    MY theme uses the following code to display recent posts on my home page …

    <?php if (have_posts()) : while (have_posts()) : the_post();
      if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>

    i want to exclude a particular category posts from recent posts .. i mean i dont want to show posts of category id ‘5’ in the recnt posts..

    how to do this..pls help me

Viewing 4 replies - 1 through 4 (of 4 total)
  • The below when put in your active themes functions file will remove category ‘1234’ from that URLs query even if there is already a category excluded or not.

    Also, if you want to remove it just from the homepage the is_home() conditional will only remove it from the homepage.

    function category_remove() {
    global $wp_query;
    $category_to_remove = 1234;
    if ( is_home() ) {
    $wp_query->query_vars['cat'] .= ( $wp_query->query_vars['cat'] == '' ) ? $category_to_remove : ','.$category_to_remove ;
    add_action('pre_get_posts', 'category_remove');

    sorry i dint understand that …

    my site is

    i want to excude category 5 posts from thr recent posts of the blog on home page ..

    please add the code using category number ‘5’.. as i dnt understand tht much php//i am just a noob here..

    thanks again

    Firstly, my virus scanner is picking up a trojan in your jQuery.js. I’m giving you the benefit of the doubt that this is unintentional.

    Secondly, there is only one ‘1234’ shown in the code making it obvious what needs changing.

    Thirdly, thanks for showing me your site now I know you wanted to filter the recent posts in your sidebar on the homepage as opposed to the most recent posts on your homepage. Usually get_posts() is used for a sidebar post list which lead me to the wrong conclusion.

    Since it is a secondary loop perhaps you should try the codex page, it even has tutorials on your specific problem to help you.

    Good day.


    firstly , when i scanned my webpages i dint find any thing..i have manually seen in my js files..but couldnt find any thing ..can u tell me what copy of antivirus are u using..

    secondly , i have understood only 1234 from the code is to be changed..can u please tell me whether i should replace my code with urs or shld i add it some where..please tell me the file name so that i can add it..

    Thirdly , i dont want it to display on sidebar ..but on home page u can find recent posts just below the featured section with the thumbnails beside them..i want to filter the code the code u have given is same for that also?

    Thank you for ur help and support ..thanks again

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘exclluding category from recent posts’ is closed to new replies.