Forums

[resolved] Exclude Multiple Categories From Blog (8 posts)

  1. w3dgie
    Member
    Posted 3 weeks ago #

    i've searched the forums and did what they said and it works... kind of...

    here's my code

    <?php if (have_posts()) : ?>
    <?php query_posts('cat=-4723,-1618'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <!--BlogStuff-->
    <?php endwhile; ?>

    it excludes both the categories, but when i go to /blog/ the first page is blank, i navigate to the next page of posts and there's only one post, then i navigate to the 3rd page and i see 3 posts in a row which is what it should be on all the pages. any idea why it's doing that?

  2. w3dgie
    Member
    Posted 3 weeks ago #

    Actually the issue from above happens when I use the following code:

    ISSUE:
    "it excludes both the categories, but when i go to /blog/ the first page is blank, i navigate to the next page of posts and there's only one post, then i navigate to the 3rd page and i see 3 posts in a row which is what it should be on all the pages. any idea why it's doing that? "

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php if (in_category('4723')) continue; ?>
    <?php if (in_category('1618')) continue; ?>
    <!--BlogStuff-->
    <?php endwhile; ?>

    The SECOND ISSUE I GET:
    It excludes the categories properly, but when I navigate to older posts it just keeps showing the same 3 posts over and over no matter how far back I go.

    While using this code:

    <?php if (have_posts()) : ?>
    <?php query_posts('cat=-4723,-1618'); ?>
    <?php while (have_posts()) : the_post(); ?>
    <!--BlogStuff-->
    <?php endwhile; ?>
  3. w3dgie
    Member
    Posted 2 weeks ago #

    I tried making a parent category called 'Blog', and putting all my previous blogging categories as child categories under the 'Blog' parent category.

    Then I tried to query the 'Blog' category displaying 3 posts per page...

    Same problem persists.

    It shows the last three posts over and over, no matter what page of posts I navigate to.

  4. avato
    Member
    Posted 2 weeks ago #

    I'm having exactly the same problem and can not work out why it's doing it. :/

    Anyone help?

  5. w3dgie
    Member
    Posted 1 week ago #

    Still haven't figured it out. Will be digging deeper to solve this issue.

  6. w3dgie
    Member
    Posted 1 week ago #

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <?php static $count = 0;
    if ($count == "N") { break; }
    else { ?>
    
    <?php if ( in_category('X') && !is_single() ) continue; ?>
    <?php if ( in_category('Y') && !is_single() ) continue; ?>
    
    <div class="post">
    <?php the_content(); ?>
    </div>
    
    <?php $count++; } ?>
    <?php endwhile; ?>
    <?php endif; ?>

    The above code doesn't work either! I don't know what to do!

  7. MichaelH
    moderator
    Posted 1 week ago #

    Not sure how you have things setup and what theme your are using...

    To exclude those categories on a blog's index.php, using the WordPress Default theme for example, in the wp-content/themes/default/index.php file, just before the line:
    <?php if (have_posts()) : ?>

    put this:

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

    The query_posts() article explains the arguments in detail.

  8. w3dgie
    Member
    Posted 1 week ago #

    Thank you so much! It worked perfectly. <3

    Where were you two weeks ago? :P

Reply

You must log in to post.

About this Topic