Skip to content

Instantly share code, notes, and snippets.

@nickdavis
Last active April 27, 2018 05:28
Show Gist options
  • Save nickdavis/862f79ca91be6a854243 to your computer and use it in GitHub Desktop.
Save nickdavis/862f79ca91be6a854243 to your computer and use it in GitHub Desktop.
Using default WordPress next / prev post links check if one exists first and update CSS classes accordingly [not complete code]
<?php
// @link http://www.jaredatchison.com/code/add-next-previous-post-links-genesis/
// Check if there are next or previous posts
// First paramter is 'in_same_term'?, make sure it matches third parameter in previous_post_link / next_post_link (which defaults to false)
$next = get_adjacent_post( false, '', false );
$previous = get_adjacent_post( false, '', true );
//Set up CSS styles to know if there are next or previous posts only
if ( ! $next ) {
echo '<ul class="article_navigation previous-only">';
}
else if ( ! $previous ) {
echo '<ul class="article_navigation next-only">';
}
else {
echo '<ul class="article_navigation">';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment