pixel-d
1/25/2018 - 8:00 PM

Next and Previous Post Links

WordPress Next and Previous Post Links

{# Using Timber #}

{# Simple version #}

{% if post.next.link is not empty %}
  <a class="pagination__prev" href="{{post.next.link}}">
    Next Post
  </a>
{% endif %}

{% if post.prev.link is not empty %}
  <a class="pagination__next" href="{{post.prev.link}}">
    Previous Post
  </a>
{% endif %}

{# Fancy version #}

{% if post.next.link is not empty %}
  <a class="pagination__prev" href="{{post.next.link}}">
    <span class="icon-angle-left-fa"></span>
    <span class="hide-sm">
      {{ function('get_limited_title', '25', post.next.id ) }}
    </span>
    <span class="show-sm">
      Next Post
    </span>
  </a>
{% endif %}

{% if post.prev.link is not empty %}
  <a class="pagination__next" href="{{post.prev.link}}">
    <span class="hide-sm">
      {{ function('get_limited_title', '25', post.prev.id ) }}
    </span>
    <span class="show-sm">
      Previous Post
    </span>
     <span class="icon-angle-right-fa"></span>
  </a>
{% endif %}
// Official WordPress functions
 
next_post_link();
previous_post_link();
 
previous_post_link('<strong>%link</strong>');
 
next_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $taxonomy = 'category' );
 
// https://codex.wordpress.org/Function_Reference/next_post_link
// https://codex.wordpress.org/Function_Reference/previous_post_link
 
// --------------------------
 
// Return just the URL of the previous post 
$prev = get_permalink(get_adjacent_post(false,'',false));
 
// Return just the URL of the next post 
$next = get_permalink(get_adjacent_post(false,'',true));