forked from mirror/_s
_s: Split navigation template tag in context-specific tags.
This commit is contained in:
parent
caff68529f
commit
3f4effb5f0
|
@ -87,7 +87,7 @@ get_header(); ?>
|
||||||
|
|
||||||
<?php endwhile; ?>
|
<?php endwhile; ?>
|
||||||
|
|
||||||
<?php _s_content_nav( 'nav-below' ); ?>
|
<?php _s_paging_nav(); ?>
|
||||||
|
|
||||||
<?php else : ?>
|
<?php else : ?>
|
||||||
|
|
||||||
|
|
|
@ -7,55 +7,63 @@
|
||||||
* @package _s
|
* @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 ) {
|
function _s_paging_nav() {
|
||||||
global $wp_query, $post;
|
// Don't print empty markup if there's only one page.
|
||||||
|
if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
|
||||||
// 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() ) ) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$nav_class = ( is_single() ) ? 'post-navigation' : 'paging-navigation';
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<nav role="navigation" id="<?php echo esc_attr( $nav_id ); ?>" class="<?php echo $nav_class; ?>">
|
<nav class="navigation paging-navigation" role="navigation">
|
||||||
<h1 class="screen-reader-text"><?php _e( 'Post navigation', '_s' ); ?></h1>
|
<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">←</span> Older posts', '_s' ) ); ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php previous_post_link( '<div class="nav-previous">%link</div>', '<span class="meta-nav">' . _x( '←', 'Previous post link', '_s' ) . '</span> %title' ); ?>
|
<?php if ( get_previous_posts_link() ) : ?>
|
||||||
<?php next_post_link( '<div class="nav-next">%link</div>', '%title <span class="meta-nav">' . _x( '→', 'Next post link', '_s' ) . '</span>' ); ?>
|
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</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 if ( get_next_posts_link() ) : ?>
|
|
||||||
<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', '_s' ) ); ?></div>
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<?php if ( get_previous_posts_link() ) : ?>
|
|
||||||
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', '_s' ) ); ?></div>
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
</nav><!-- #<?php echo esc_html( $nav_id ); ?> -->
|
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
endif; // _s_content_nav
|
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 );
|
||||||
|
|
||||||
|
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 previous_post_link( '%link', _x( '<span class="meta-nav">←</span> %title', 'Previous post link', '_s' ) ); ?>
|
||||||
|
<?php next_post_link( '%link', _x( '%title <span class="meta-nav">→</span>', 'Next post link', '_s' ) ); ?>
|
||||||
|
|
||||||
|
</div><!-- .nav-links -->
|
||||||
|
</nav><!-- .navigation -->
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
endif;
|
||||||
|
|
||||||
if ( ! function_exists( '_s_comment' ) ) :
|
if ( ! function_exists( '_s_comment' ) ) :
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -31,7 +31,7 @@ get_header(); ?>
|
||||||
|
|
||||||
<?php endwhile; ?>
|
<?php endwhile; ?>
|
||||||
|
|
||||||
<?php _s_content_nav( 'nav-below' ); ?>
|
<?php _s_paging_nav(); ?>
|
||||||
|
|
||||||
<?php else : ?>
|
<?php else : ?>
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ get_header(); ?>
|
||||||
|
|
||||||
<?php endwhile; ?>
|
<?php endwhile; ?>
|
||||||
|
|
||||||
<?php _s_content_nav( 'nav-below' ); ?>
|
<?php _s_paging_nav(); ?>
|
||||||
|
|
||||||
<?php else : ?>
|
<?php else : ?>
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ get_header(); ?>
|
||||||
|
|
||||||
<?php get_template_part( 'content', 'single' ); ?>
|
<?php get_template_part( 'content', 'single' ); ?>
|
||||||
|
|
||||||
<?php _s_content_nav( 'nav-below' ); ?>
|
<?php _s_post_nav(); ?>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
// If comments are open or we have at least one comment, load up the comment template
|
// If comments are open or we have at least one comment, load up the comment template
|
||||||
|
|
Reference in New Issue