Advertisement
g4ry

Single View Nav

Apr 24th, 2011
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. <?php
  2. $currentPost = (array)$post;
  3.  
  4. unset($currentPost['ancestors']);
  5. $currentPost = (object)$currentPost;
  6.  
  7. $args = array( 'category_name' => 'events',
  8. 'post_status' => 'publish',
  9. 'meta_key' => '_EventStartDate',
  10. 'orderby' => 'meta_value',
  11. 'order' => 'ASC',
  12. 'posts_per_page'=> '-1' );
  13. $query = new WP_Query( $args );
  14.  
  15. $queryPosts = $query->posts;
  16. $postKey = array_search( $currentPost, $queryPosts );
  17.  
  18. if ( $postKey > 0 ) {
  19. $prevTitle = $queryPosts[ $postKey-1 ]->post_title;
  20. $prevLink = site_url().'/?p='.$queryPosts[ $postKey-1 ]->ID;
  21. }
  22. if ( $postKey < count( $queryPosts ) ) {
  23. $nextTitle = $queryPosts[ $postKey+1 ]->post_title;
  24. $nextLink = site_url().'/?p='.$queryPosts[ $postKey+1 ]->ID;
  25. } ?>
  26.  
  27. <div class="tec-nav" id="tec-nav-below"><?php /* Use the same nav id and class style as found in list.php */ ?>
  28. <?php if ( !empty($prevTitle) ) {
  29. echo ('<div class="tec-nav-previous alignleft"><a href="'.$prevLink.'">&laquo; '.$prevTitle.'</a></div>'); }
  30. if ( !empty($nextTitle) ) {
  31. echo ('<div class="tec-nav-next alignright"><a href="'.$nextLink.'">'.$nextTitle.' &raquo;</a></div>'); }
  32. ?>
  33. <div style="clear: both;"></div>
  34. </div><!-- #tec-nav-below -->
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement