• Resolved dunkkan

    (@dunkkan)


    Hi guys,

    I’m querying posts in my index.php like that :

    <?php
    		query_posts('offset=1');
    		if (have_posts()) :
    		while (have_posts()) :
    	      the_post();
    		?>
    		<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    		<?php the_excerpt(); ?>
    		<?php endwhile;
    		endif;
    		?>

    Then, I’m adding a next_posts_link but it brings me again in the same index.php.

    Do you know how to solve this ?

    Many thanks for any help;

    D.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Try:
    query_posts($query_string . '&offset=1');

    If that doesn’t work may look at use the

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts($paged . '&offset=1');

    Thread Starter dunkkan

    (@dunkkan)

    Awesome !

    Here’s my final code :

    <?php query_posts ($query_string.'offset=1') ; ?>
    		<?php
    		if (have_posts()) :
    		while (have_posts()) :
    	      the_post();
    		?>
    		<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    		<?php the_excerpt(); ?>
    		<?php endwhile;
    		endif;
    		?>

    I just deleted the & , which seemed to interfere in '&offset=1');.

    Many thanks.

    I just deleted the & , which seemed to interfere in ‘&offset=1’);.

    Don’t know why that is working…

    Thread Starter dunkkan

    (@dunkkan)

    It doesn’t seems to need the ‘&’ as a “connector”, maybe because there’s only one parameter : the offset ?

    It’s in fact my main loop in index.php, and the only special parameter would be that offset (before that, I have another loop with a wp_query).

    But don’t trust me, I’m not sure to do things totally right (even if the pagination works now), so any clarification would be cool.

    I was filtering posts on a single page with the function call ‘query_posts’ and noticed after a while the same problem as the original poster (Dunkkan) – the unabillity to sift through older and newer posts with the next_posts_link or previous_posts_link call, and it was easily addressed to the query_post function, since if I turned it off, everything worked fine.

    this seems to solve it. I’m not sure for how long though, since I’m quite novice to php and wordpress altogether. I make of use of the get_query_var and dynamically add the appropriate paged number to the offset variable.

    <?php
        //get the categories...
        $submissions = get_cat_ID( 'submissions' );
        $inspiration = get_cat_ID( 'inspiration' );
        $finalist = get_cat_ID( 'finalist' );
        $crew = get_cat_ID( 'crew' );
    
    	if(intval(get_query_var('paged'))>1){
    		$offset = '&offset='.((get_query_var('paged')-1)*10);
    	}else{
    		$offset = '&offset=0';
    	}
    
    	$querystring = 'cat='. $submissions.','.$inspiration.','.$finalist.','.$offset;
    	?>
    
        <!--begin query-->
        <?php query_posts($querystring.'&showposts=10'); ?>
    
    	<?php if (have_posts()) : ?>...
    
    ...<?php endif; ?>
    
        <!--end query-->
        <?php wp_reset_query(); ?>

    sorry about that!
    lost the category filtering due to a typo in the code above…

    this:
    $querystring = 'cat='. $submissions.','.$inspiration.','.$finalist.','.$offset;

    should be this:
    $querystring = 'cat='. $submissions.','.$inspiration.','.$finalist.$offset;

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Querying posts Next Posts Link in Index’ is closed to new replies.