1

When clicking the next_posts_link it just shows the same posts as on page 1. It appears to work fine on the category pages and it is only affecting the homepage (home.php)

Thanks!

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
<?php query_posts('cat=-683,-3598' . $paged); ?>

FULL CODE

    <?php get_header(); ?>
    <div id="featured">
            <div id="featured_left">
                <div id="block1">
                <?php query_posts('cat=3598&showposts=1'); ?>
<?php while(have_posts()) : the_post(); ?>

<?php the_post_thumbnail('fbox12'); ?>

<?php endwhile; ?>

                </div>
                <div id="block2">
                <?php query_posts('cat=3598&showposts=1&offset=1'); ?>
<?php while(have_posts()) : the_post(); ?>

<?php the_post_thumbnail('fbox12'); ?>

<?php endwhile; ?>

                </div>
            </div>
            <div id="featured_middle">
                <div id="block3">
                <?php query_posts('cat=3598&showposts=1&offset=2'); ?>
<?php while(have_posts()) : the_post(); ?>

<?php the_post_thumbnail('fbox3'); ?>

<?php endwhile; ?>

                </div>
                <div id="block6">
                <?php query_posts('cat=3598&showposts=1&offset=3'); ?>
<?php while(have_posts()) : the_post(); ?>

<?php the_post_thumbnail('fbox67'); ?>

<?php endwhile; ?>

                </div>
                <div id="block7">
                <?php query_posts('cat=3598&showposts=1&offset=4'); ?>
<?php while(have_posts()) : the_post(); ?>

<?php the_post_thumbnail('fbox67'); ?>

<?php endwhile; ?>

                </div>
            </div>
            <div id="featured_right">
                <div id="block4">
                <?php query_posts('cat=3598&showposts=1&offset=5'); ?>
<?php while(have_posts()) : the_post(); ?>

<?php the_post_thumbnail('fbox45'); ?>

<?php endwhile; ?>

                </div>



            </div>
        </div>


        <div id="left">
        <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
   <?php query_posts('cat=-683,-3598&paged=' . $paged); ?>

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                <div class="post_item">
        <?php
if ( has_post_thumbnail() ) {
?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_post_thumbnail('homepage-thumb'); ?></a>
<?php }
else { ?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/no_thumb.png"/></a>
<?php }
?>
        <h2><?php the_category(', '); ?> | <?php the_time('F j, Y'); ?></h2>
        <h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
        <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_excerpt(); ?></a>
                </div>
                <?php endwhile; ?>
                    <?php endif; ?>
        <div class="pagenav">
<div class="pagenavright"><?php next_posts_link('Next Entries','') ?></div>
</div> <!-- end navigation -->          
        </div>

    <?php get_sidebar(); ?>

    </div>

<?php get_footer(); ?>
0

Don't use query_posts, ever.

The first 6 queries can be condensed to a single WP_Query:

$args = array(
    'cat' => 3598,
    'posts_per_page' => 6
);

$featured = new WP_Query( $args );

if( $featured->have_posts() ){

    $featured->the_post();
    ?>
    your markup for the first post
    <?php

    $featured->the_post();
    ?>
    your markup for the second post
    <?php

    $featured->the_post();
    // etc..

    wp_reset_postdata();
}

For the main query, use the pre_get_posts action with a function in your theme's functions.php. This avoids wasting a query when you overwrite it in the template.

function wpa_exclude_categories( $query ) {
    if ( $query->is_home() && $query->is_main_query() ) {
        $query->set( 'category__not_in', array( 683, 3598 ) );
    }
}
add_action( 'pre_get_posts', 'wpa_exclude_categories' );

You've now chopped 6 queries from every page load, and your pagination will magically work, do a little dance.

0
<?php query_posts('cat=-683,-3598' . $paged); ?>

This line should be

<?php query_posts('cat=-683,-3598&paged=' . $paged); ?>
  • Still not working. – Storm3y Jan 16 '14 at 18:48
  • Can you post full code of homepage template here ? – Abdul Awal Jan 16 '14 at 18:50
  • Added to the post above. Cheers! – Storm3y Jan 16 '14 at 18:53
  • Appears to be becuase of multiple query_posts – Storm3y Jan 16 '14 at 19:00
  • 1
    don't use query_posts, ever. – Milo Jan 16 '14 at 19:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.