Support » Fixing WordPress » Next/Previous Post URL only

  • Hi guys,

    I’m looking on the documentation and googling it, but I just can’t find anything, which is weird, ’cause it seems to be a simple thing.

    You know, the functions: next_post_link and previous_post_link.

    But I want them to show ONLY the URL, without any text. Like, I wish to make a tag like this:

    <a href="<?php next_post_link(URL) ?>?variable=value"> Here some text </a>

    Could you help me, please?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Anyone, please?

    Those are for pages.

    I tried to make the function code for posts, but it still doesn’t work.

    Here goes the code I made:

    $postlist = get_posts();
    $posts = array();
    foreach ($postlist as $post) {
    	$posts[] += $post->ID;
    $current = array_search($post->ID, $posts);
    $prevID = $posts[$current-1];
    $nextID = $posts[$current+1];
    // Link for previous post
    if (!empty($prevID)) {
    	echo '<div><a href="'. get_permalink($prevID) .'?variable=true">Msg. Anterior</a></div>';
    // Link for next post
    if (!empty($nextID)) {
    	echo '<div><a href="'. get_permalink($nextID) .'?variable=true">Pr&oacute;xima Msg.</a></div>';

    Im looking for the same thing!! Its rare.. I hope someone can solved this.



    Forum Moderator

    there is an undocumented function ‘get_next_post()’:

    <?php $nepo=get_next_post(); $nepoid=$nepo->ID;
    $next_post_url = get_permalink($nepoid); ?>
    <?php $prpo=get_previous_post(); $prpoid=$prpo->ID;
    $prev_post_url = get_permalink($prpoid); ?>

    if there is no next/prev – the above will contain the link url of the last post at the respective end.

    in these cases, it could be useful to define a fixed url:

    <?php $nepo=get_next_post(); if($nepo) { $nepoid=$nepo->ID;
    $next_post_url = get_permalink($nepoid); } else { $next_post_url = '#'; ?>

    Here you go:

    Previous Post:
    <?php echo get_permalink(get_adjacent_post(false,”,false)); ?>

    Next Post:
    <?php echo get_permalink(get_adjacent_post(false,”,true)); ?>

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Next/Previous Post URL only’ is closed to new replies.