Title: Super Loop modifications
Last modified: August 20, 2016

---

# Super Loop modifications

 *  [lil_bugga](https://wordpress.org/support/users/lil_bugga/)
 * (@lil_bugga)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/super-loop-modifications/)
 * 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](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)

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/super-loop-modifications/#post-2941227)
 * with 5 years old, that post is a bit of a stoneage hack;
 * try to work with `WP_Query()` or `query_posts()` and the `'category__not_in'`
   parameter.
 * [http://codex.wordpress.org/Function_Reference/query_posts#Preserving_Existing_Query_Parameters](http://codex.wordpress.org/Function_Reference/query_posts#Preserving_Existing_Query_Parameters)
   
   [http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters](http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters)
 * example – to be added **before **the line with `if( have_posts() )`:
 *     ```
       global $wp_query;
       $args = array_merge( $wp_query->query, array( 'category__not_in' => array(8) ) );
       query_posts( $args );
       ```
   

Viewing 1 replies (of 1 total)

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

 * 1 reply
 * 2 participants
 * Last reply from: [Michael](https://wordpress.org/support/users/alchymyth/)
 * Last activity: [13 years, 9 months ago](https://wordpress.org/support/topic/super-loop-modifications/#post-2941227)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
