WordPress.org

Ready to get started?Download WordPress

Forums

previous_post_link(); and next_post_link(); Not Working (2 posts)

  1. wicknbomb
    Member
    Posted 5 years ago #

    Hi -

    I've looked through the forums and all the examples I see for using the previous_post_link(); and next_post_link(); don't seem to work for my page template.

    Some background

    I have set up a category called "news" (cat_id=5). In this category are a series of posts (17 in all). I'd like to show the first 10 within the page template, then have simple previous/next links at the bottom of the page that links to the remaining 7 posts. I've confirmed that I've created a page and assigned it to the template code below:

    <?php
    /*
    Template Name: Template G - News Listing Page
    */
    ?>
    
    <?php get_header(); ?>
    
    <div id="content" class="<?php the_title(); ?> widecolumn">
      <?php
      $newsposts = get_posts('category_name=news&numberposts=10&order=DESC'); /* restrict category, show max 10 posts and order DESC */
      foreach($newsposts as $post) :
         setup_postdata($post);
      ?>
      <h2><?php the_date(); ?></h2>
      <h3><a><"div id="post-<?php the_ID(); ?>"><?php the_title(); ?></a></h3>
      <?php the_content(); ?>
    
      <?php previous_post_link(); ?> <?php next_post_link(); ?>
      <?php endforeach; ?>  
    
    </div>
    <?php get_footer(); ?>
    <em>Template G - News Listing Page</em>

    The news page renders just fine and spits out the first 10 posts in question, but for some reason the pagination's HTML is not rendered and no errors are thrown. Any suggestions?

    Thanks in advance,

    wickNbomb

  2. brandondrury
    Member
    Posted 5 years ago #

    I'm doing something similar. It appears the next_post_link and previous_post_link are specific for posts and not pages.

    Did you ever whip up a custom solution or find one? If not, I guess I could write out the function. It shouldn't be difficult.

    Brandon

Topic Closed

This topic has been closed to new replies.

About this Topic