WordPress.org

Ready to get started?Download WordPress

Forums

How to navigate to "next post/previous post" (16 posts)

  1. Alan
    Member
    Posted 10 years ago #

    I've found in the Wiki these navigation tags but can't seem to get them to work:

    <?php next_posts(max); ?>
    <?php previous_posts(); ?>
    <?php next_posts_link('label', max); ?>
    <?php previous_posts_link('label'); ?>
    Used by posts_nav_link, below.
    <?php posts_nav_link('separator', 'previous', 'next'); ?>
    Displays navigation showing next and previous pages. This tag must be within "the loop".
    Parameters:
    'seperator' - string - The seperator between the links. Defaults to ' :: '.
    'previous' - string - The link text for the previous page. Defaults to '« Previous Page'.
    'next' - string - The link text for the next page. Defaults to 'Next Page »'.

    Would some WP PHP expert please explain how to use these navigation tags?

  2. carthik
    Member
    Posted 10 years ago #

    >>Would some WP PHP expert please explain how to use these navigation tags? - That disqualifies a lot of people, including me, who are no php experts. I will hazard an answer, though :)
    The following, from "START" to "END", in index.php is what is fondly called "the loop":
    <?php if ($posts) { foreach ($posts as $post)"START" { start_wp(); ?>
    <?php the_date('','<h2>','</h2>'); ?>
    <div class="post">
    <h3 class="storytitle" id="post-<?php the_ID(); ?>">" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"><?php the_title(); ?></h3>
    <div class="meta">Filed under: <?php the_category() ?> — <?php the_author() ?> @ <?php the_time() ?> <?php edit_post_link(); ?></div>
    <div class="storycontent">
    <?php the_content(); ?>
    </div>
    <div class="feedback">
    <?php link_pages('
    Pages: ', '
    ', 'number'); ?>
    <?php comments_popup_link('Comments (0)', 'Comments (1)', 'Comments (%)'); ?>
    </div>
    <!--
    <?php trackback_rdf(); ?>
    -->
    <?php include(ABSPATH . 'wp-comments.php'); ?>
    </div>
    <?php } }"END" else { // end foreach, end if any posts ?>

    If wanted to display reverse $#$ forward on the index page, I would use
    <?php posts_nav_link('$#$', 'reverse', 'forward'); ?>
    just before the </div> on the second last line of the code I have posted above(which is taken from the index.php file).

  3. tedfox
    Member
    Posted 10 years ago #

    I got the same problem too.... and i'm using the latest nightly built. erm. so somehow... plastering
    <?php posts_nav_link() ?>
    returned nothing too. Tat's as basic and default a code as it gets. Any help??

  4. OperaManiac
    Member
    Posted 10 years ago #

    put this:
    <?php posts_nav_link() ?>
    below this:
    '<?php } } else { // end foreach, end if any posts ?>
    Sorry, no posts matched your criteria.
    <?php } ?>'

  5. Alan
    Member
    Posted 10 years ago #

    The code, whether inside or outside "The Loop", returns nothing. It's like an include file or function is not being...included.

  6. tedfox
    Member
    Posted 10 years ago #

    I agree with Alan
    Once again... state. I'm using the apr 19th nightly.
    I plastered the code all over the php file. Nothing gets echoed out. In or out of the loop. (other support threads says to put it outside, wiki says to put it inside, so i just put it everywhere)
    So I proceed to change the code abit.... maybe i'm just calling it wrongly. but hey!! errors abound.
    So basically the function SHOULD be calling correctly... but nothing is being echoed out. boohoo... :(:(
    *btw... thanks to Sushubh for replying to all my problemetic posts all over the forums*

  7. Ozh
    Member
    Posted 10 years ago #

    (Same for me, using 1.02)

  8. Alan
    Member
    Posted 10 years ago #

    I ask Mr. X on his blog and he posted the snippet of code he uses.....evidently I wasn't using the correct functions. This code works and from within "The Loop":
    <?php previous_post('%', '&laquo previous', 'no', 'no', 1, '') ?>
    " title="home">home
    <?php next_post('%', 'next &raquo', 'no', 'no', 1, '') ?>

  9. OperaManiac
    Member
    Posted 10 years ago #

    ok u do know u have to select post paged from the options menu in the backend?

  10. tedfox
    Member
    Posted 10 years ago #

    Ok. this is going to make me sound real stupid. But I can't find any post paged options in the options for the lastest build.
    But hey!! Mr X's code works.... but <?php posts_nav_link() ?> returns blank. Ah wellz. as long as something works!
    Thanks to alan and sushubh and mr X. woot

  11. OperaManiac
    Member
    Posted 10 years ago #

    check this option:
    Show the most recent:
    there is a drop down.

  12. carthik
    Member
    Posted 10 years ago #

    @tedfox, depending on what version you are running, the posts pages option is at different locations...
    in 1.0.2 it's under options->other options-> what to show
    in 1.2 latest cvs/nightly it is under options->reading->show the most recent -> drop down menu.
    Take it easy...:)

  13. Anonymous
    Unregistered
    Posted 10 years ago #

    Woo found it!!!
    Love u peeps. Though I still can't get <?php posts_nav_link() ?> to work. hahaha. BUt hey! i got the options now. heh. And well.. MR X's code still works. So all's well!
    Looking forward to learning PHP and helping answer stuff in this forums

  14. randybrown
    Member
    Posted 10 years ago #

    I've added:
    <?php posts_nav_link(' :: ', 'previous', 'next'); ?>
    ... inside "the loop" at the bottom. The previous/next links are appearing at the end of each post. I want it to appear only at the bottom of the page.
    Any ideas? Thanks.

  15. Ryan Boren
    WordPress Dev
    Posted 10 years ago #

    Move it outside of the loop. You can put it right before the end of the content div.

  16. randybrown
    Member
    Posted 10 years ago #

    Thanks, rboren. That worked. I'll see if I can make this change to the wiki docs.
    <rb>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.