How To Show Naked URL For Previous & Next Post In WP?

by satrap
6 replies
Hi Guys,

You know the previous and next post links that show up under posts in WP, how can you change the code so it only shows the naked URL of the previous and next post, instead of the hyper linked title of the post?...

Example:


Normally it looks like...

Next post 1 New Thread On WF
Previous post 1 New Post On WF

But I want it to look like...

Next Post http://www.warriorforum.com/newthread
Previous Post http://www.warriorforum.com/newpost

Thank you in advance.
#naked #post #previous #show #url
  • Profile picture of the author tajimd
    <?php
    $next_post_link_url = get_permalink( get_adjacent_post(false,'',false)->ID );
    $prev_post_link_url = get_permalink( get_adjacent_post(false,'',true)->ID );
    ?>
    <div id="nav-above" class="navigation">
    <div class="nav-previous"><?php echo $prev_post_link_url; ?></div>
    <div class="nav-next"><?php echo $next_post_link_url; ?></div>
    </div>

    Try using the above code and see if this works for you or not.

    But please remember, this is not actually paginating the posts.

    The above code only finds the previous and next adjacent posts of the current post and shows its Permalink.

    For More, check this page on WP Codes:
    Function Reference/get adjacent post « WordPress Codex
    {{ DiscussionBoard.errors[7159517].message }}
    • Profile picture of the author satrap
      Originally Posted by tajimd View Post

      <?php
      = get_permalink( get_adjacent_post(false,'',false)->ID );
      = get_permalink( get_adjacent_post(false,'',true)->ID );
      ?>
      <div id="nav-above" class="navigation">
      <div class="nav-previous"><?php echo ; ?></div>
      <div class="nav-next"><?php echo ; ?></div>
      </div>

      Try using the above code and see if this works for you or not.

      But please remember, this is not actually paginating the posts.

      The above code only finds the previous and next adjacent posts of the current post and shows its Permalink.

      For More, check this page on WP Codes:
      Function Reference/get adjacent post « WordPress Codex
      Hi,

      Thanks for this. But this doesn't make the naked url clickable, it just shows the naked url as a normal text and not a clickable link?...

      Thanks.
      Signature
      60 Awesome Ways to Make Money Without a Job
      .................................
      Check out my blog Survey Satrap featuring honest reviews of paid survey sites.
      {{ DiscussionBoard.errors[7163922].message }}
  • Profile picture of the author boilingstocks
    All you need to do is alter the text between this code <a href="Link to your next/last post">THIS TEXT NEEDS TO BE ALTERED</a>
    {{ DiscussionBoard.errors[7159561].message }}
  • Profile picture of the author tajimd
    Ah, right, That's easy to fix.

    here is updated code. Just add href to the links

    <?php
    $next_post_link_url = get_permalink( get_adjacent_post(false,'',false)->ID );
    $prev_post_link_url = get_permalink( get_adjacent_post(false,'',true)->ID );
    ?>
    <div id="nav-above" class="navigation">
    <div class="nav-previous"><a href="<?php echo $prev_post_link_url; ?>"><?php echo $prev_post_link_url; ?></a></div>
    <div class="nav-next"><a href="<?php echo $next_post_link_url; ?>"><?php echo $next_post_link_url; ?></a></div>
    </div>
    {{ DiscussionBoard.errors[7164169].message }}
    • Profile picture of the author satrap
      Originally Posted by tajimd View Post

      Ah, right, That's easy to fix.

      here is updated code. Just add href to the links
      ...
      Thank you very much. it has worked beautifully.

      By the way, since it was just showing the links on top of each other and I wanted to have them align left and right, I edited the code and got them to do that.

      But since I am not savvy with coding, I just wanted to make sure everything is ok and I didn't escrow anything up that's going to bite me later. Here is the code:
      PHP Code:
                    <div class="navigation">
      <?php
       
      get_permalinkget_adjacent_post(false,'',false)->ID );
       = 
      get_permalinkget_adjacent_post(false,'',true)->ID );
      ?>
                  <div class="alignleft"><a href="<?php echo ; ?>"><?php echo ; ?></a></div>
                  <div class="alignright"><a href="<?php echo ; ?>"><?php echo ; ?></a></div>
              </div>
      Does everything look ok?...

      Thank you very much for taking time to help. I really appreciate your help.
      Signature
      60 Awesome Ways to Make Money Without a Job
      .................................
      Check out my blog Survey Satrap featuring honest reviews of paid survey sites.
      {{ DiscussionBoard.errors[7175295].message }}
  • Profile picture of the author tajimd
    Yeap, looks good...
    {{ DiscussionBoard.errors[7175510].message }}

Trending Topics