Skip to content

Commit 0a7af8d

Browse files
committed
Twenty Twelve: Fix post navigation to respect sort order.
Change the labels on post navigation links when the sort order is changed so the labels accurately reflect the target entries. Previously, if the sort order was reversed, 'Older' or 'Previous' links would navigate to newer entries and 'Newer' or 'Next' links would navigate to older entries. Props jikamens, dancameron, obenland, shrey0shrivastava, sirlouen, sabernhardt, shailu25, westonruter, joedolson. See #10219. git-svn-id: https://develop.svn.wordpress.org/trunk@61095 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 6f0cb01 commit 0a7af8d

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

src/wp-content/themes/twentytwelve/functions.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,28 @@ function wp_get_list_item_separator() {
413413
function twentytwelve_content_nav( $html_id ) {
414414
global $wp_query;
415415

416-
if ( $wp_query->max_num_pages > 1 ) : ?>
416+
if ( $wp_query->max_num_pages > 1 ) :
417+
$order = get_query_var( 'order', 'DESC' );
418+
$is_desc = ( 'DESC' === $order );
419+
420+
$new_posts_text = __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentytwelve' );
421+
$old_posts_text = __( '<span class="meta-nav">&larr;</span> Older posts', 'twentytwelve' );
422+
423+
$prev_link = $is_desc ? get_next_posts_link( $old_posts_text ) : get_previous_posts_link( $old_posts_text );
424+
$next_link = $is_desc ? get_previous_posts_link( $new_posts_text ) : get_next_posts_link( $new_posts_text );
425+
?>
417426
<nav id="<?php echo esc_attr( $html_id ); ?>" class="navigation">
418427
<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3>
419-
<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentytwelve' ) ); ?></div>
420-
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentytwelve' ) ); ?></div>
428+
<?php if ( $prev_link ) : ?>
429+
<div class="nav-previous"><?php echo $prev_link; ?></div>
430+
<?php endif; ?>
431+
432+
<?php if ( $next_link ) : ?>
433+
<div class="nav-next"><?php echo $next_link; ?></div>
434+
<?php endif; ?>
421435
</nav><!-- .navigation -->
422436
<?php
423-
endif;
437+
endif;
424438
}
425439
endif;
426440

0 commit comments

Comments
 (0)