Skip to content
Browse files

_s: Split navigation template tag in context-specific tags.

  • Loading branch information...
1 parent caff685 commit 3f4effb5f0dfe62fb7c2704938cebf3605d681f6 @obenland obenland committed Nov 24, 2013
Showing with 47 additions and 39 deletions.
  1. +1 −1 archive.php
  2. +43 −35 inc/template-tags.php
  3. +1 −1 index.php
  4. +1 −1 search.php
  5. +1 −1 single.php
View
2 archive.php
@@ -87,7 +87,7 @@
<?php endwhile; ?>
- <?php _s_content_nav( 'nav-below' ); ?>
+ <?php _s_paging_nav(); ?>
<?php else : ?>
View
78 inc/template-tags.php
@@ -7,55 +7,63 @@
* @package _s
*/
-if ( ! function_exists( '_s_content_nav' ) ) :
+if ( ! function_exists( '_s_paging_nav' ) ) :
/**
- * Display navigation to next/previous pages when applicable.
+ * Display navigation to next/previous set of posts when applicable.
+ *
+ * @return void
*/
-function _s_content_nav( $nav_id ) {
- global $wp_query, $post;
-
- // Don't print empty markup on single pages if there's nowhere to navigate.
- if ( is_single() ) {
- $previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true );
- $next = get_adjacent_post( false, '', false );
-
- if ( ! $next && ! $previous ) {
- return;
- }
- }
-
- // Don't print empty markup in archives if there's only one page.
- if ( $wp_query->max_num_pages < 2 && ( is_home() || is_archive() || is_search() ) ) {
+function _s_paging_nav() {
+ // Don't print empty markup if there's only one page.
+ if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
return;
}
-
- $nav_class = ( is_single() ) ? 'post-navigation' : 'paging-navigation';
-
?>
- <nav role="navigation" id="<?php echo esc_attr( $nav_id ); ?>" class="<?php echo $nav_class; ?>">
- <h1 class="screen-reader-text"><?php _e( 'Post navigation', '_s' ); ?></h1>
+ <nav class="navigation paging-navigation" role="navigation">
+ <h1 class="screen-reader-text"><?php _e( 'Posts navigation', '_s' ); ?></h1>
+ <div class="nav-links">
- <?php if ( is_single() ) : // navigation links for single posts ?>
+ <?php if ( get_next_posts_link() ) : ?>
+ <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', '_s' ) ); ?></div>
+ <?php endif; ?>
- <?php previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '&larr;', 'Previous post link', '_s' ) . '</span> %title' ); ?>
- <?php next_post_link( '<div class="nav-next">%link</div>', '%title <span class="meta-nav">' . _x( '&rarr;', 'Next post link', '_s' ) . '</span>' ); ?>
+ <?php if ( get_previous_posts_link() ) : ?>
+ <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', '_s' ) ); ?></div>
+ <?php endif; ?>
- <?php elseif ( $wp_query->max_num_pages > 1 && ( is_home() || is_archive() || is_search() ) ) : // navigation links for home, archive, and search pages ?>
+ </div><!-- .nav-links -->
+ </nav><!-- .navigation -->
+ <?php
+}
+endif;
- <?php if ( get_next_posts_link() ) : ?>
- <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', '_s' ) ); ?></div>
- <?php endif; ?>
+if ( ! function_exists( '_s_post_nav' ) ) :
+/**
+ * Display navigation to next/previous post when applicable.
+ *
+ * @return void
+ */
+function _s_post_nav() {
+ // Don't print empty markup if there's nowhere to navigate.
+ $previous = ( is_attachment() ) ? get_post( get_post()->post_parent ) : get_adjacent_post( false, '', true );
+ $next = get_adjacent_post( false, '', false );
- <?php if ( get_previous_posts_link() ) : ?>
- <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', '_s' ) ); ?></div>
- <?php endif; ?>
+ if ( ! $next && ! $previous ) {
+ return;
+ }
+ ?>
+ <nav class="navigation post-navigation" role="navigation">
+ <h1 class="screen-reader-text"><?php _e( 'Post navigation', '_s' ); ?></h1>
+ <div class="nav-links">
- <?php endif; ?>
+ <?php previous_post_link( '%link', _x( '<span class="meta-nav">&larr;</span> %title', 'Previous post link', '_s' ) ); ?>
+ <?php next_post_link( '%link', _x( '%title <span class="meta-nav">&rarr;</span>', 'Next post link', '_s' ) ); ?>
- </nav><!-- #<?php echo esc_html( $nav_id ); ?> -->
+ </div><!-- .nav-links -->
+ </nav><!-- .navigation -->
<?php
}
-endif; // _s_content_nav
+endif;
if ( ! function_exists( '_s_comment' ) ) :
/**
View
2 index.php
@@ -31,7 +31,7 @@
<?php endwhile; ?>
- <?php _s_content_nav( 'nav-below' ); ?>
+ <?php _s_paging_nav(); ?>
<?php else : ?>
View
2 search.php
@@ -23,7 +23,7 @@
<?php endwhile; ?>
- <?php _s_content_nav( 'nav-below' ); ?>
+ <?php _s_paging_nav(); ?>
<?php else : ?>
View
2 single.php
@@ -14,7 +14,7 @@
<?php get_template_part( 'content', 'single' ); ?>
- <?php _s_content_nav( 'nav-below' ); ?>
+ <?php _s_post_nav(); ?>
<?php
// If comments are open or we have at least one comment, load up the comment template

0 comments on commit 3f4effb

Please sign in to comment.
Something went wrong with that request. Please try again.