Ask your WordPress questions! Pay money and get answers fast! (more info)

Prev/Next post links. WordPress

  • SOLVED

I am trying to place this in my templates:

<?php my_prev_next(); ?>

and this in my functions to be able to insert prev/next links on my posts. Currently it displays nothing.


function my_prev_next() {
if ( is_single() ) {
echo '<div class="navigation">';
previous_posts_link('<div class="navalignleft">%link</div>', '%title', TRUE);
next_posts_link('<div class="navalignright">%link</div>', '%title', TRUE);
echo '</div>';
}
}
add_action( 'my_before_comments', 'my_prev_next' );


Any solutions please?

Answers (3)

2014-02-14

Navjot Singh answers:

Its previous_post and not posts. Same is with next_post not next_posts. Fix that.


Navjot Singh comments:

Change it to


function my_prev_next() {

if ( is_single() ) {
echo '<div class="navigation">';
previous_post_link('<div class="navalignleft">%link</div>', '%title', TRUE);
next_post_link('<div class="navalignright">%link</div>', '%title', TRUE);
echo '</div>';
}
}
add_action( 'my_before_comments', 'my_prev_next' );


julesphoto comments:

That did it. Thanks.


Navjot Singh comments:

Am glad to hear it. If nothing else, please close the question by voting.

2014-02-14

Hariprasad Vijayan answers:

Hello,
Try this


function my_prev_next() {
if ( is_single() ) {
echo '<div class="navigation">';
previous_post_link('<div class="navalignleft">%link</div>', '%title', TRUE);
next_post_link('<div class="navalignright">%link</div>', '%title', TRUE);
echo '</div>';
}
}
add_action('the_content','my_prev_next');


Hariprasad Vijayan comments:

Hello,
Try this


function my_prev_next() {
if ( is_single() ) {
echo '<div class="navigation">';
previous_posts_link('<div class="navalignleft">%link</div>', '%title', TRUE);
next_posts_link('<div class="navalignright">%link</div>', '%title', TRUE);
echo '</div>';
}
}
add_action('the_content','my_prev_next');

2014-02-14

Sabby Sam answers:

Hi,
The <?php previous_posts_link( $label ); ?> content only one parameter, you should remove the extra things.
see the link here
http://codex.wordpress.org/Function_Reference/previous_posts_link.
Similar for next one as well.