WordPress.org

Ready to get started?Download WordPress

Forums

Problem Excluding Categories using query_posts on index.php (2 posts)

  1. johnnydugs
    Member
    Posted 1 year ago #

    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(); ?>
  2. vtxyzzy
    Member
    Posted 1 year ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic