WordPress.org

Forums

next page previous page (9 posts)

  1. 24lover
    Member
    Posted 4 years ago #

    hi everyone!
    i've currently got the following code in my page.php

    <div class="prenextlink">
    <div class="prenextlinkleft">
    <?php previous_post('« « %',
    'Previous: ', 'yes'); ?>
    </div>
    <div class="prenextlinkright">
    <?php next_post('% » » ',
    'Next: ', 'yes'); ?>
    </div>
    </div> <!-- end navigation -->

    however, the problem is I don't know how to connect up the pages so that a visitor can properly navigate through previous and next pages. At the moment it's just random pages that is popping up for the previous and next page links. Can anyone help? i'm sorry if this is confusing!
    kind regards!

  2. 24lover
    Member
    Posted 4 years ago #

    bump?! can anyone help?
    much appreciated

  3. Sennza Pty Ltd
    Member
    Posted 4 years ago #

    Hey there,

    Try using these lines of code instead:

    <?php /* Display navigation to next/previous pages when applicable */ ?>
    <?php if ( $wp_query->max_num_pages > 1 ) : ?>
    	<div id="nav-above" class="navigation">
    		<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyten' ) ); ?></div>
    		<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?></div>
    	</div><!-- #nav-above -->
    <?php endif; ?>

    That's taken from the Twenty Ten theme that ships with WordPress so that should work a treat.

  4. 24lover
    Member
    Posted 4 years ago #

    unfortunately that code doesn't work :(

    i'm trying to make it like sparknotes because my website is full of books :(

  5. Sennza Pty Ltd
    Member
    Posted 4 years ago #

    Hmm if that doesn't work then it sounds like there might be something wrong with you WordPress Loop.

    Can you please post all the code in your page.php here? That way I can see how you are doing the loop and see if I can recommend an adjustment for you :)

    Thanks!

  6. 24lover
    Member
    Posted 4 years ago #

    <?php get_header(); ?>
    <div style="clear:both; margin:0px auto; width:728px;">
    <script type="text/javascript"><!--
    google_ad_client = "pub-1054015025474255";
    /* 728x15, created 11/29/10 */
    google_ad_slot = "7888810450";
    google_ad_width = 728;
    google_ad_height = 15;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>
    </div>
    
    <!-- START: content -->
    <div id="content">
    
    <?php
    if( is_page('encountering-conflict') || $post->post_parent == '194' || $post->post_parent == '215'  ){
      get_sidebar('enc');
    }
    else if(is_page('blog')) {
    	get_sidebar('blog');
    }
    else{
      get_sidebar('alt');
    }
    ?>
    
    <!-- START: content-article -->
    <div id="content-article">
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    	<div class="post">
    		<h2><?php the_title(); ?></h2>
    		<?php the_content(''); ?>
    		<p><?php edit_post_link('&uarr; edit this page'); ?></p>
    	</div>
    
    <?php endwhile; ?>
    
    <?php /* Display navigation to next/previous pages when applicable */ ?>
    <?php if ( $wp_query->max_num_pages > 1 ) : ?>
    	<div id="nav-above" class="navigation">
    		<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyten' ) ); ?></div>
    		<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?></div>
    	</div><!-- #nav-above -->
    <?php endif; ?>
    
    <!-- START: navigation -->
    <div class="navigation">
    	<div class="alignleft"><?php next_posts_link('&larr; Previous Entries') ?></div>
    	<div class="alignright"><?php previous_posts_link('Next Entries &rarr;') ?></div>
    </div>
    <!-- END: navigation -->
    
    <?php else : ?>
    
    <div class="post">
    	<h2 class="center">Not Found</h2>
    	<p class="center">Sorry, but we don't have this on our website yet!</p>
    </div>
    
    <?php endif; ?>
    </div>
    <div class="navigation"><p><?php posts_nav_link('∞','Go
    Forward In Time','Go Back in Time'); ?></p></div>
    
    <!-- END: content-article -->
    
    <?php get_sidebar(); ?>
    
    </div>
    <!-- END: content -->
    <?php get_footer(); ?>

    thanks bronson!

  7. Sennza Pty Ltd
    Member
    Posted 4 years ago #

    Cheers for that. Try moving the line:
    <?php endwhile; ?>
    so that it's underneath
    <!-- END: content-article -->

    I think you're closing the WordPress Loop too early from the looks of it. I haven't tested it on a site yet so if that doesn't work then let me know and I'll upload that to one of my sites and have another look.

  8. 24lover
    Member
    Posted 4 years ago #

    thanks for your reply

    i tried your method and it came up with an error, but when i put the code just below the next/previous code it was ok. however it still doesn't show up. Is this because i need to put a code into the particular pages i want to have next/previous links? Or is there something else additional i need to do after having that code in page.php
    regards!

  9. Sennza Pty Ltd
    Member
    Posted 4 years ago #

    Oh wait a second. I'm an idiot. It only just clicked that this is for a page and not a post. Have a go with this code instead:

    <?php
    $pagelist = get_pages('sort_column=menu_order&sort_order=asc');
    $pages = array();
    foreach ($pagelist as $page) {
       $pages[] += $page->ID;
    }
    
    $current = array_search($post->ID, $pages);
    $prevID = $pages[$current-1];
    $nextID = $pages[$current+1];
    ?>
    
    <div class="navigation">
    <?php if (!empty($prevID)) { ?>
    <div class="alignleft">
    <a href="<?php echo get_permalink($prevID); ?>"
      title="<?php echo get_the_title($prevID); ?>">Previous</a>
    </div>
    <?php }
    if (!empty($nextID)) { ?>
    <div class="alignright">
    <a href="<?php echo get_permalink($nextID); ?>"
     title="<?php echo get_the_title($nextID); ?>">Next</a>
    </div>
    <?php } ?>
    </div><!-- .navigation -->

    which is from Next and previous links

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.