WordPress.org

Ready to get started?Download WordPress

Forums

Using posts_nav_link in a non standard template (5 posts)

  1. andreacimatti
    Member
    Posted 8 years ago #

    I was wondering if it was possible to use posts_nav_link in a template page that is not standard (i.e index.php, category.php...)
    something like this:
    <?php
    $posts = get_posts('numberposts=5');
    foreach($posts as $post) :
    ?>
    "><?php the_title(); ?>
    <?php the_excerpt(); ?>
    <?php endforeach; ?>
    <?php posts_nav_link(' — ', __('« Previous Page'), __('Next Page »')); ?>

    I've tried this of course but it does not seem to work.
    Are there alternatives that cam be used?

  2. moshu
    Member
    Posted 8 years ago #

    Is this a Page template? In that case it will not work: Pages are meant to display ONE single content and (out of the box) there is no next/prev navigation for them.

  3. andreacimatti
    Member
    Posted 8 years ago #

    Yes, my question regards Page Templates.
    I was wondering if anybody knew of a hack or a workaround
    that permitted me to have on a Page Template something similar to prev/next seeing that I using a simple foreach loop I can show within that Page a limited number of posts at a time.
    I'm one of the many who would like to use WordPress as a light CMS and each time that I try other platforms I come back to WordPress.

    I am wondering the prev/next could be possible or if I am going on a dead end street.

  4. Michael Bishop

    Posted 8 years ago #

    Template_Tags/wp_link_pages give that a try? I'm just throwing it out there, I've not tried it myself.

  5. andreacimatti
    Member
    Posted 8 years ago #

    The wp_link_pages is a good idea however the problem remains.
    I think that it's because both posts_nav_link and wp_link_pages can only be used within the Loop and the Loop does not work in Page Templates.

    So at the moment I think that I will try to resolve the issue hard coding a next link.

    Thank you for your ideas.

Topic Closed

This topic has been closed to new replies.

About this Topic