• Resolved w3dgie

    (@w3dgie)


    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?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter w3dgie

    (@w3dgie)

    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; ?>
    Thread Starter w3dgie

    (@w3dgie)

    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.

    avato

    (@avato)

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

    Anyone help?

    Thread Starter w3dgie

    (@w3dgie)

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

    Thread Starter w3dgie

    (@w3dgie)

    <?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!

    MichaelH

    (@michaelh)

    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.

    Thread Starter w3dgie

    (@w3dgie)

    Thank you so much! It worked perfectly. <3

    Where were you two weeks ago? ??

    Hello guys

    The problem excluding cat′s with <?php query_posts($query_string . '&cat=-4723,-1618'); ?> is when you want use the $query_string coming from another page with, i.e., cat=6. In this cases, you are defining twice the cat variable inside the query_posts() function and the result is a query for the last definition.

    I recommend, for this cases, something as:

    <?php $myCats = array(12,27,31); // Excluded Categories
          query_posts($query_string); // Requested variables
          if(have_posts()) :while (have_posts()) : the_post();
          if(in_category($myCats)) continue;
    ?>
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Exclude Multiple Categories From Blog’ is closed to new replies.