• Whilst trying to find a soloution for excluding specific categories form the main loop on index.php I stumbled across this page http://perishablepress.com/super-loop-exclude-specific-categories-and-display-any-number-of-posts/#comments

    I’ve used the code there to and adapted it slightly and the code works well and excludes any post with a category id of 8. The only issue I’ve found is that setting the page to display 10 posts is fine, but as I have 9 posts from the excluded category on my first page I only have one post actually display.

    I’ve looked and tried to modify the loop myself to prevent it from incimenting $count if the post is from category 8 but to no avail.

    Hopefully someone on here might be able to help me with this. This is the code I’m using.

    <?php
    /**
     * The main template file.
     *
     * This is the most generic template file in a WordPress theme
     * and one of the two required files for a theme (the other being style.css).
     * It is used to display a page when nothing more specific matches a query.
     * E.g., it puts together the home page when no home.php file exists.
     * Learn more: http://codex.wordpress.org/Template_Hierarchy
     *
     * @package WordPress
     * @subpackage Bare
     * @since Bare 1.0
     */
    
    get_header(); ?>
    
    		<h1>index.php</h1>
    
    <?php get_sidebar();
    
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    
    static $count = 0;
    if ($count == "10") { break; }
    else { 
    
    if ( in_category('8') ) continue; ?>
    
    <div class="post">
    <h2><?php the_title(); ?></h2>
    <?php the_content(); ?>
    </div>
    
    <?php $count++; }
    endwhile;
    endif; ?>
    
    <div class="navigation"><p><?php posts_nav_link('∞','&laquo;&laquo; Go Forward
    In Time','Go Back in Time &raquo;&raquo;'); ?></p></div>
    
      <?php get_footer('footer'); ?>

    I’ve tried lots of different things including
    if ( in_category('8') ) $count-1; continue;

    <div class="post">
    <h2><?php the_title(); ?></h2>
    <?php the_content(); ?>
    <?php $count++; ?>
    </div>
    
    <?php  }

    I’m not used to coding php if statments in this format so I think thats where part of my confusion is coming from, but when I tried to convert it to an if () { } else {} style stament and ending up breaking the code completly hence I’ve left things unchanged atm.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Super Loop modifications’ is closed to new replies.