Forums

[resolved] Help: Exclude category messing Loop (6 posts)

  1. kishorebudha
    Member
    Posted 4 years ago #

    Here is my problem:

    a) I want a category to be excluded from the loop
    b) I have applied <?php if (in_category('x') && !is_single() ) continue; ?>
    c) Out of the 10 latest posts, 9 belong to category x.
    d) The home page only displays 1 post.

    Following the tip at Perishable Press here, I have modified my index.php as below to add a counter. I have tried changing it to > 10. Yet only one post is being displayed. The blog Reading Settings is set at 10 posts.

    What am I doing wrong?

    <?php 		if (have_posts()) : ?>
    
    			<div id="content_inner">
    <?php
    			while (have_posts()) : the_post(); ?>
    
    	<?php static $count = 0;
    	if ($count == "10")
    	{ break; }else { ?>
    
    	<?php if (in_category('88')) continue; ?>
    
    					<h2<?php if ($post_count == 1) echo(' class="top"'); ?>><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
    					<p class="post_author"><span class="date"><?php the_time('F j, Y') ?></span>&nbsp;|&nbsp;<em>by</em> <?php the_author_posts_link(); ?></p>
    					<div class="format_text">
    <?php the_content('[Read more &rarr;]'); ?>
    					</div>
    					<p class="to_comments"><span class="num_comments"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></span>
    					<!-- Share this-->&nbsp; <?php if (function_exists('sharethis_button')) { sharethis_button(); } ?>
    					<!-- Edit Post Tag--><?php edit_post_link('Edit This', '<span class="edit_post">&nbsp;', '</span>'); ?>
    					</p>
    
    <?php $post_count++; ?>
    
    <?php $count++; } ?>
    
    <?php endwhile; ?>
  2. kishorebudha
    Member
    Posted 4 years ago #

    See it in action here. The 9 posts before the one here are from the excluded category. The previous posts page similarly deducts the excluded category posts from the page view.

  3. kishorebudha
    Member
    Posted 4 years ago #

    OK. Resolved the issue by placing query posts in index.php

    <?php
       if (is_home()) {
          query_posts("cat=-88");
       }
    ?>
  4. rodsherwin
    Member
    Posted 4 years ago #

    Actually, this won't fix your problem in 2.6.1 because the previous pages keep bringing up the same posts. You used to be able to fix this with the code in this forum post but it no longer works in 2.6.1.

    Haven't found a fix yet.

  5. kishorebudha
    Member
    Posted 4 years ago #

    rodsherwin: Thanks very much for pointing that out. I did not bother to test it out thoroughly.

    This worked:

    <?php
    if (is_home()) {
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("cat=-88&paged=$paged");
    }
    ?>
  6. dreamyguy
    Member
    Posted 3 years ago #

    Thanks for sharing it, it's working great on a blog I'm developing. I too tried to use the:

    <?php if (in_category('88')) continue; ?>

    ...but the pagination included all the other posts. The only one post which was not in the category (somewhat similar to your case) was showing only on the last page :P

    Your way is bullet-proof!

Topic Closed

This topic has been closed to new replies.

About this Topic