Title: Problem Excluding Categories using query_posts on index.php
Last modified: August 20, 2016

---

# Problem Excluding Categories using query_posts on index.php

 *  [johnnydugs](https://wordpress.org/support/users/johnnydugs/)
 * (@johnnydugs)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/problem-excluding-categories-using-query_posts-on-indexphp/)
 * Hey Folks,
 * I have my front page setup as a static page which uses a custom page template.
   My blog is setup as a page in the WordPress admin and uses the default, index.
   php template. I am trying to prevent my photos from showing up on my blog. Photos
   are stored in the category with an id of 6. My attempt at using the query_posts
   function to modify the default loop is not working. Index.php code below:
 *     ```
       <?php
       /**
        * The main template file.
        *
        * @package _s
        * @since _s 1.0
        */
   
       get_header(); ?>
   
       		<?php
       			global $query_string; // grab the global query information
       			$posts = query_posts($query_string.'&cat=-6'); // exclude Photos category
       			if ( have_posts() ) :
       		?>
   
       			<div class="grid">
       				<div class="span12" role="navigation">
       					<?php _s_content_nav( 'navbar-top' ); ?>
       				</div> <!-- .span12 -->
       			</div> <!-- .grid -->
   
       			<?php /* Start the Loop */ ?>
       			<div class="grid" role="main">
       				<?php while ( have_posts() ) : the_post(); ?>
   
       					<div class="span6">
       						<div class="module module-entry">
       							<?php
       								/* Include the Post-Format-specific template for the content.
       								 * If you want to overload this in a child theme then include a file
       								 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
       								 */
       								get_template_part( 'content', get_post_format() );
       							?>
       						</div> <!-- .module -->
       					</div> <!-- .span6 -->
   
       				<?php endwhile; ?>
       			</div> <!-- .grid -->
   
       			<div class="grid">
       				<div class="span12" role="navigation">
       					<?php _s_content_nav( 'navbar-bottom' ); ?>
       				</div>
       			</div>
   
       		<?php else : ?>
   
       			<div class="grid">
       				<div class="span12">
       					<?php get_template_part( 'no-results', 'index' ); ?>
       				</div> <!-- .span12 -->
       			</div> <!-- .grid -->
   
       		<?php
       			endif;
       			wp_reset_query();
       		?>
   
       <?php get_footer(); ?>
       ```
   

Viewing 1 replies (of 1 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/problem-excluding-categories-using-query_posts-on-indexphp/#post-3320602)
 * Just a guess, but try replacing this:
 *     ```
       $posts = query_posts($query_string.'&cat=-6'); // exclude Photos category
       ```
   
 * with this:
 *     ```
       query_posts($query_string.'&cat=-6'); // exclude Photos category
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Problem Excluding Categories using query_posts on index.php’ is closed
to new replies.

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/problem-excluding-categories-using-query_posts-on-indexphp/#post-3320602)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
