Advertisement
Guest User

Vantage Content Nav

a guest
Dec 18th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. if ( ! function_exists( 'vantage_content_nav' ) ) :
  2. /**
  3. * Display navigation to next/previous pages when applicable
  4. *
  5. * @since vantage 1.0
  6. */
  7. function vantage_content_nav( $nav_id ) {
  8. $jetpack_infinite_scroll_active = class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'infinite-scroll' );
  9. //Check if we're in the Page Builder Post Loop widget.
  10. $is_page_builder_post_loop_widget = class_exists( 'SiteOrigin_Panels_Widgets_PostLoop' ) &&
  11. method_exists( 'SiteOrigin_Panels_Widgets_PostLoop', 'is_rendering_loop' ) &&
  12. SiteOrigin_Panels_Widgets_PostLoop::is_rendering_loop();
  13.  
  14. if( $jetpack_infinite_scroll_active && ! $is_page_builder_post_loop_widget ) {
  15. return;
  16. }
  17. global $wp_query, $post;
  18.  
  19. // Don't print empty markup on single pages if there's nowhere to navigate.
  20. if ( is_single() ) {
  21. $previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
  22. $next = get_adjacent_post( false, '', false );
  23.  
  24. if ( ! $next && ! $previous )
  25. return;
  26. }
  27.  
  28. // Don't print empty markup in archives if there's only one page.
  29. if ( $wp_query->max_num_pages < 2 && ( is_home() || is_archive() || is_search() ) )
  30. return;
  31.  
  32. // Add the shorten title filter
  33. add_filter('the_title', 'vantage_content_nav_shorten_title');
  34.  
  35. $nav_class = 'site-navigation paging-navigation';
  36. if ( is_single() )
  37. $nav_class = 'site-navigation post-navigation';
  38.  
  39. ?>
  40. <nav role="navigation" id="<?php echo esc_attr( $nav_id ); ?>" class="<?php echo $nav_class; ?>">
  41. <h1 class="assistive-text"><?php _e( 'Post navigation', 'vantage' ); ?></h1>
  42.  
  43. <?php if ( is_single() ) : // navigation links for single posts ?>
  44.  
  45. <div class="single-nav-wrapper">
  46. <?php previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '&larr;', 'Previous post link', 'vantage' ) . '</span> %title' ); ?>
  47. <?php next_post_link( '<div class="nav-next">%link</div>', '%title <span class="meta-nav">' . _x( '&rarr;', 'Next post link', 'vantage' ) . '</span>' ); ?>
  48. </div>
  49.  
  50. <?php elseif ( $wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_search() ) ) : // navigation links for home, archive, and search pages ?>
  51.  
  52. <?php vantage_pagination() ?>
  53.  
  54. <?php endif; ?>
  55.  
  56. </nav><!-- #<?php echo esc_html( $nav_id ); ?> -->
  57. <?php
  58.  
  59. // Remove the shorten title filter
  60. remove_filter('the_title', 'vantage_content_nav_shorten_title');
  61. }
  62. endif; // vantage_content_nav
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement