Last active
July 12, 2018 16:08
-
-
Save martifenosa/e5abdcacd4b97cd3fba438c4d2bd6fc2 to your computer and use it in GitHub Desktop.
Functions that returns either next or prev post id or the url. Infinte Wordpress Posts Loop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* --------------------------------------------------------------------------- | |
* INFINITE PREV-NEXT POSTS LINKS (o id) | |
* --------------------------------------------------------------------------- */ | |
function prevPostLink() { | |
if( get_adjacent_post(false, '', false) ) { | |
$postLink = get_permalink(get_adjacent_post(false,'',false)); | |
} else { | |
$first = new WP_Query('posts_per_page=1&order=DESC'); $first->the_post(); | |
$postLink = get_permalink(); | |
wp_reset_query(); | |
}; | |
return $postLink; | |
} | |
function nextPostLink() { | |
if( get_adjacent_post(false, '', true) ) { | |
$postLink = get_permalink(get_adjacent_post(false,'',true)); | |
} else { | |
$last = new WP_Query('posts_per_page=1&order=ASC'); $last->the_post(); | |
$postLink = get_permalink(); | |
wp_reset_query(); | |
}; | |
return $postLink; | |
} | |
function prevPostId() { | |
if( get_adjacent_post(false, '', false) ) { | |
$post = get_adjacent_post(false,'',false); | |
} else { | |
$first = new WP_Query('posts_per_page=1&order=DESC'); $first->the_post(); | |
$post = get_post(); | |
wp_reset_query(); | |
}; | |
return $post->ID; | |
} | |
function nextPostId() { | |
if( get_adjacent_post(false, '', true) ) { | |
$post = get_adjacent_post(false,'',true); | |
} else { | |
$last = new WP_Query('posts_per_page=1&order=ASC'); $last->the_post(); | |
$post = get_post(); | |
wp_reset_query(); | |
}; | |
return $post->ID; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based -> https://gist.github.com/banago/5603826 (full prev-next post wordpress function)