Created
August 14, 2013 05:16
-
-
Save fael/6228203 to your computer and use it in GitHub Desktop.
Get adjacent posts from a term of a custom taxonomy
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
<?php | |
function next_prev_portfolio($post, $current_term){ | |
//echo '<pre>'; | |
$postlist_args = array( | |
'posts_per_page' => -1, | |
//'orderby' => 'menu_order title', | |
//'order' => 'ASC', | |
'post_type' => 'portfolio', | |
'portfolio_category' => $current_term | |
); | |
$postlist = get_posts( $postlist_args ); | |
$ids = array(); | |
foreach ($postlist as $thepost) { | |
$ids[] = $thepost->ID; | |
} | |
$thisindex = array_search($post->ID, $ids); | |
$previd = $ids[$thisindex-1]; | |
$nextid = $ids[$thisindex+1]; | |
if ( !empty($previd) ) { | |
echo '<a class="styled-link next-link" title="' . get_the_title($previd) . '" href="' . get_permalink($previd). '"><span> </span></a>'; | |
} | |
if ( !empty($nextid) ) { | |
echo '<a class="styled-link prev-link" title="' . get_the_title($nextid) . '" href="' . get_permalink($nextid). '"><span> </span></a>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment