Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Get only the URL from Next / Prev link WordPress

  • SOLVED

I have the code:
<a href="" id="psingle_prev" class="psingle_bts clearfix"><span class="psingle_arrow" id="arrow_prev">&nbsp;</span> Previous</a>
<a href="" id="psingle_next" class="psingle_bts clearfix">Next <span class="psingle_arrow" id="arrow_next">&nbsp;</span></a>


I would like to add the url for <strong>href=""</strong>, dynamically using a PHP function.

Answers (3)

2010-11-23

Nick Parsons answers:

Try this:
<?php echo strip_tags( get_next_posts_link() ); ?>


Lucian Florian comments:

outputs nothing


Nick Parsons comments:

Sorry, working on it. Just realized my mistake!


Nick Parsons comments:

OK, update:

<?php $next_post = get_adjacent_post(false,'',true) ; echo get_permalink($next_post); ?>


Nick Parsons comments:

Your code would look like:

<a href="<?php echo get_permalink(get_adjacent_post(false,'',false)); ?>" id="psingle_prev" class="psingle_bts clearfix"><span class="psingle_arrow" id="arrow_prev">&nbsp;</span> Previous</a>
<a href="<?php echo get_permalink(get_adjacent_post(false,'',true)); ?>" id="psingle_next" class="psingle_bts clearfix">Next <span class="psingle_arrow" id="arrow_next">&nbsp;</span></a>


Lucian Florian comments:

good job, thank you.

2010-11-23

MagoryNET answers:

Rather:


echo next_posts();
echo previous_posts();


Lucian Florian comments:

outputs nothing

2010-11-23

Michael Fields answers:

One of these depending on which type of view you are targeting:

$prev = get_previous_post();
if ( isset( $prev->ID ) ) {
$url = get_permalink( $prev->ID );
}

$next = get_next_post();
if ( isset( $next->ID ) ) {
$url = get_permalink( $next->ID );
}