• Hi.

    I created a loop for parent pages. But i have a problem with nav links at the end of the loop.

    When i clik next page it go to https://www.domain.com/page-permalink/page/2 but posts wont’change.

    Can someone help me please.

    CODE:

    <?php if ( have_posts() ) {  /* Query and display the parent. */
    	while ( have_posts() ) {
    	the_post();
    	the_content();
    	$thispage=$post->ID;
    	}
    } ?>
    
    <?php $childpages = query_posts('post_per_page=3&orderby=menu_order&order=asc&post_type=page&post_parent='.$thispage);
    	if($childpages){ /* display the children content  */
    	       	foreach ($childpages as $post) :
    	        setup_postdata($post); ?>
    	        <h2><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    
                <!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->
     <small><?php the_time('j. F, Y') ?></small>
    
    		<?php the_content();?>
                  <hr />
    	 <?php
    	  endforeach;
    	 } ?>
    
    <!-- Nav link Pages -->
    
    <div class="navigation"><p><?php posts_nav_link('∞','&laquo;&laquo; Previous page','Next page &raquo;&raquo;'); ?></p></div>
    
    <!-- Nav links Pages -->
Viewing 6 replies - 1 through 6 (of 6 total)
  • Try using get_posts() instead of query_posts() for the child pages.

    Thread Starter Martin

    (@mcundric)

    If i use get_posts(), the nav links disappear.

    Any other ideas?

    From the code you posted, it looks like the nav links are inside the main loop. Move them just after the endwhile.

    Thread Starter Martin

    (@mcundric)

    I put it out of the loop div, but it won’t work.
    I’m new to loop programing and i don’t now how to put the links after endwhile.

    Link to the template site: https://bit.ly/fNEgw9

    TEMPLATE CODE:

    <?php
    /*
    Template Name: Sporo?ila za medije
    */
    ?>
    
    <?php get_header(); ?>
    
    <div id="content" class="inner clearfix">
    
        <div id="content-sub">
    		<?php get_sidebar(); ?>
    	</div> <!-- end #content-sub -->
    
    <div style="width: 655px; float: right;">
    
    <?php if ( have_posts() ) {  /* Query and display the parent. */
    	while ( have_posts() ) {
    	the_post();
    	the_content();
    	$thispage=$post->ID;
    	}
    } ?>
    
    <?php $childpages = query_posts('post_per_page=3&orderby=menu_order&order=asc&post_type=page&post_parent='.$thispage);
    	if($childpages){ /* display the children content  */
    	       	foreach ($childpages as $post) :
    	        setup_postdata($post); ?>
    	        <h2><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
    
                <!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. -->
     <small><?php the_time('j. F, Y') ?></small>
    
    		<?php the_content();?>
                  <hr />
    	 <?php
    	  endforeach;
    	 } ?>
    
      <!-- Nav link Pages -->
    
    <div class="navigation"><p><?php posts_nav_link('∞','&laquo;&laquo; Previous page','Next page &raquo;&raquo;'); ?></p></div>
    
    <!-- Nav links Pages -->  
    
    </div>
    
    </div><!-- end #content -->
    <?php get_footer(); ?>

    Is it posible that you fix the code and you put nav link after endwhile?

    OK – I think the problem is that you are trying to paginate the ‘child pages’, but the main query loop (which is normally paginated) is only showing the one parent post.

    Your child query does not include the ‘paged’ argument. Try adding it like this:

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $childpages = query_posts('paged=' . $paged . '&posts_per_page=3&orderby=menu_order&order=asc&post_type=page&post_parent='.$thispage);

    Notice also that I changed the ‘post_per_page’ to ‘posts_per_page’.

    Thread Starter Martin

    (@mcundric)

    Perfect!

    Thanx for help and have a nice day!

    m

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Custom page loop problem with "Next and Previous Links" at the end of the loop’ is closed to new replies.