Created
August 4, 2013 23:23
-
-
Save cherihung/49a65b31348fe9729eac to your computer and use it in GitHub Desktop.
create prev/next nav for custom post type. something that works like this plugin http://wordpress.org/plugins/previous-and-next-post-in-same-taxonomy/ but can offer order by menu order
This file contains 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
//from this post http://bucketpress.com/next-and-previous-post-link-in-same-custom-taxonomy | |
// get_posts in same custom taxonomy | |
$postlist_args = array( | |
'posts_per_page' => -1, | |
'orderby' => 'menu_order title', | |
'order' => 'ASC', | |
'post_type' => 'your_custom_post_type', | |
'your_custom_taxonomy' => 'your_custom_taxonomy_term' | |
); | |
$postlist = get_posts( $postlist_args ); | |
// get ids of posts retrieved from get_posts | |
$ids = array(); | |
foreach ($postlist as $thepost) { | |
$ids[] = $thepost->ID; | |
} | |
// get and echo previous and next post in the same taxonomy | |
$thisindex = array_search($post->ID, $ids); | |
$previd = $ids[$thisindex-1]; | |
$nextid = $ids[$thisindex+1]; | |
if ( !empty($previd) ) { | |
echo '<a rel="prev" href="' . get_permalink($previd). '">previous</a>'; | |
} | |
if ( !empty($nextid) ) { | |
echo '<a rel="next" href="' . get_permalink($nextid). '">next</a>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment