• I know this has been asked like a milion times, and I red the tutorial
    http://codex.ww.wp.xz.cn/Template_Tags/query_posts
    and I have added the code in my index.php file but to no avail.

    I’m using a child theme and I have inserted the index.php inside the child theme folder but it doesnt work.

    What I’m doing wrong?

    Here is my index.php file:

    <?php get_header(); ?>
    
    	<?php include (TEMPLATEPATH . "/sidebar.php"); ?>
    
    	<?php include (TEMPLATEPATH . "/navigation.php"); ?>        
    
     <!-- LOOP1 -->
     	<?php
    	if (is_home()) {
    	query_posts("cat=-3");}
    	//Exclude posts in category 3 from the home page
    
    	?>
        <?php if (have_posts()) : ?>
        <?php while (have_posts()) : the_post(); ?>
        <div class="post one"<?php echo (is_category() || is_tag())? 'style="border-bottom: 1px solid #e0e0e0 !important; border-top: none !important;"' : ''; ?>>
    		<div class="sepia">
    			<?php
    			if ( has_post_thumbnail() ) { ?>
                        	<?php
                        	$imgsrcparam = array(
    						'alt'	=> trim(strip_tags( $post->post_excerpt )),
    						'title'	=> trim(strip_tags( $post->post_title )),
    						);
                        	$thumbID = get_the_post_thumbnail( $post->ID, 'one', $imgsrcparam ); ?>
                            <div class="preview"><a href="<?php the_permalink() ?>"><?php echo "$thumbID"; ?></a></div>
    
                        <?php } else {?>
                            <div class="preview"><a href="<?php the_permalink() ?>"><img src="<?php bloginfo('template_url'); ?>/images/default-thumbnail.jpg" alt="<?php the_title(); ?>" /></a></div>
                        <?php } ?>
            </div><!-- .sepia -->
            <h2><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
            <?php the_excerpt(); ?>
            <div class="time"><?php the_time('M, d'); ?></div>
    	</div>
       	<?php endwhile; ?>
       	<?php else : ?>
    	<?php endif; ?>
        <!-- #LOOP1 -->
    
        <div class="aside"<?php echo (is_category() || is_tag())? 'style="border-bottom: 1px solid #e0e0e0 !important; border-top: none !important;"' : ''; ?>>
            <h3>Navigation</h3>
            <p>Please use the navigation to move within this section.</p>
            <p><?php next_posts_link('Next'); ?>
            <?php previous_posts_link('Prev'); ?>
            </p>
        </div>
    
    <?php get_footer(); ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • Give this a try: http://pastebin.com/Ut2ZBeCJ

    Thread Starter achpav

    (@achpav)

    thanks Andrew, but it didn’t work…

    What could it be? Is there something else that keeps the posts appearing on the home page even though they are excluded in the index.php?

    I mean I tried with other categories, they all show up…

    Thread Starter achpav

    (@achpav)

    maybe I should modify my home.php file?

    <?php get_header(); ?>
    
    	<?php include (TEMPLATEPATH . "/sidebar.php"); ?>
        <?php
            if ( $paged == 0 ) {
                $offset1 = 0;
                $offset2 = 2;
            } else {
                $off = $paged - 1;
                $offset1 = $off * 7;
                $offset2 = $off * 7 + 2;
            }
        ?>
        <?php
    $sticky = get_option( 'sticky_posts' );
    $args = array(
    	'posts_per_page' => 3,
    	'post__in'  => $sticky,
    	'ignore_sticky_posts' => 3
    );
    query_posts( $args );
    if ( $sticky[0] ) {
    	// insert here your stuff...
    }?>
        <!-- LOOP1 -->
        <?php if (have_posts()) : ?>
    	<?php query_posts($args); ?>
        <?php while (have_posts()) : the_post(); ?>
        <div class="post two">
    		<div class="sepia">
    
    			<?php
    			if ( has_post_thumbnail() ) { ?>
                        	<?php
                        	$imgsrcparam = array(
    						'alt'	=> trim(strip_tags( $post->post_excerpt )),
    						'title'	=> trim(strip_tags( $post->post_title )),
    						);
                        	$thumbID = get_the_post_thumbnail( $post->ID, 'two', $imgsrcparam ); ?>
                            <div class="preview"><a href="<?php the_permalink() ?>"><?php echo "$thumbID"; ?></a></div>
    
                        <?php } else {?>
                            <div class="preview"><a href="<?php the_permalink() ?>"><img src="<?php bloginfo('template_url'); ?>/images/default-thumbnail.jpg" alt="<?php the_title(); ?>" /></a></div>
                        <?php } ?>
    
            </div><!-- .sepia -->
            <h2><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
            <?php the_excerpt(); ?>
            <div class="time"><?php the_time('M, d'); ?> &middot; in <?php the_category(','); ?></div>
    	</div>
       	<?php endwhile; ?>
       	<?php else : ?>
    	<?php endif; ?>
        <?php wp_reset_query(); ?>
        <!-- #LOOP1 --> 
    
       	<!-- LOOP2 -->
        <?php if (have_posts()) : ?>
    	<?php query_posts(array( 'post__not_in' => get_option( 'sticky_posts' ) )); ?>
        <?php while (have_posts()) : the_post(); ?>
        <div class="post one"<?php echo (is_home())? 'style="border-bottom: none !important;"' : ''; ?>>
    		<div class="sepia">
    
    			<?php
    			if ( has_post_thumbnail() ) { ?>
                        	<?php
                        	$imgsrcparam = array(
    						'alt'	=> trim(strip_tags( $post->post_excerpt )),
    						'title'	=> trim(strip_tags( $post->post_title )),
    						);
                        	$thumbID = get_the_post_thumbnail( $post->ID, 'one', $imgsrcparam ); ?>
                            <div class="preview"><a href="<?php the_permalink() ?>"><?php echo "$thumbID"; ?></a></div>
    
                        <?php } else {?>
                            <div class="preview"><a href="<?php the_permalink() ?>"><img src="<?php bloginfo('template_url'); ?>/images/default-thumbnail.jpg" alt="<?php the_title(); ?>" /></a></div>
                        <?php } ?>
    
            </div><!-- .sepia -->
            <h2><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
            <?php the_excerpt(); ?>
            <div class="time"><?php the_time('M, d'); ?></div>
    	</div>
       	<?php endwhile; ?>
       	<?php else : ?>
    	<?php endif; ?>
        <?php wp_reset_query(); ?>
        <!-- #LOOP2 -->
        <div style="clear: both;"></div>
        <?php include (TEMPLATEPATH . "/bottom.php"); ?>
    
    <?php get_footer(); ?>
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Exclude specific category from front page’ is closed to new replies.