Home Forums Theme Support Cassiopeia Hiding a category from the loop on the blog page

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #3221

    Hello again,

    I’m trying to hide the posts from a certain category from the blog page it kinda works but the title of the blog page is now the title of the last post from the category that I’m hiding.

    I’m using the following code to hide the posts from the blog page.

    <?php query_posts($query_string . '&cat=-5'); ?>

    Thanks for your time 🙂

    #3239

    Hi there,

    Are you trying to do this on the blog page? If so, try instead of your query to change the default query, this:

    $wp_query->query('showposts='.$data['number_blogposts'].''.'&paged='.$paged);

    to this:

    $wp_query->query('cat=-5'&showposts='.$data['number_blogposts'].''.'&paged='.$paged);

    Cheers!
    Chris

    #3245

    I’m trying it on the index page but I can try to make it work on the blog page.

    Thanks

    Edit: I tried and got an nasty division by zero error 🙁

    #3274

    Hi there,

    I managed to fix it using the following code:

    <?php
    function excludeCat($query) {
      if ( $query->is_home ) {
        $query->set('cat', '-21');
      }
      return $query;
    }
    add_filter('pre_get_posts', 'excludeCat');
    ?>

    Where 21 is the category that I want to hide.

    Cheers 😀

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.