Forums

[resolved] excluded categories in home.php but published posts are counted towards total (10 posts)

  1. Piet
    Member
    Posted 2 years ago #

    Hi, I'm struggling with the following:

    I made a site with a home.php template and I am listing only the excerpts there of the posts.

    I have also excluded 2 categories and I publish those separately with 2 different templates.

    But on the homepage after a mere 6 published posts (total of 12) the page navigation already shows up.

    Is there a way to exclude the posts from the excluded categories also for the published-post-count in the navigation?

    website is winesofvalencia.com

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    What are you using to exclude the categories in the Loop? get_posts or query_posts?

  3. Piet
    Member
    Posted 2 years ago #

    hi esmi, thanks for your quick response.

    I'm using neither...

    What I am using is
    <?php if (in_category(array('7','13'))) continue; ?>

    where cat 7 and 13 are the excluded ones...

  4. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    In that case, that's where the problem is. You'd be better of using query_posts to construct a custom query along the lines of:

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	'category__not_in' => array(7,13),
    	'paged' => $paged
    );
    query_posts($args);
    ?>
  5. Piet
    Member
    Posted 2 years ago #

    cool, thanks i will try that and let you know how it goes

  6. Piet
    Member
    Posted 2 years ago #

    works brilliantly!

    thanks a lot for the solution and the speed!

  7. Piet
    Member
    Posted 2 years ago #

    sorry esmi, i guess i celebrated too early.

    as you can see on the site, it is not working at all as page navigation is completely broken now.

    problems now are:
    1) second page never shows up
    2) post(s) of excluded category are
    a) counted towards the total
    b) showing up in the list

    I remember I had this problem before and that is why I came up (after some search) with <?php if (in_category(array('7','13'))) continue; ?>

    is there a solution that works?

  8. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    That should work. It's lifted straight from the relevant Codex page with the added fix in to handle paging. Are you using a page navigation plugin? I wonder if that is causing a problem?

  9. Piet
    Member
    Posted 2 years ago #

    yeah i'm using the famous PageNavi by Lester Chan, I will first disable that and try to get it working first without.

    Loads of people have the same problem and all he does is referring to the codex: Template_Tags/query_posts

    Could be an idea for him to write "The definite Tutorial on PageNavi"...

  10. Piet
    Member
    Posted 2 years ago #

    yeah sorry for that, all is working perfect.

    I forgot to reset the query, so that messed it all up. Again sorry for that and thanks for the responses!

Topic Closed

This topic has been closed to new replies.

About this Topic