0

I am using a child theme derived from twentythirteen. I wanted to have my posts displayed in chronological order(ascending). I tried adding the code from this answer to index.php but for some reason that didn't seem to work. So instead I got the plugin "Advanced Post Types Order" and that seemed to work fine, in regards to displaying the posts in the right order.

However now when I want to display a single post, the navigation links are backwards. It displays:

enter image description here

The two links should be just reversed, i.e.

<-- post #1 for the "previous" post, and post#3 --> for the "next" post.

I looked at file single.php, and found it was calling twentythirteen_post_nav() in functions.php. And inside that function, I found the two lines:

   <?php previous_post_link( '%link', _x( '<span class="meta-nav">&larr;</span> %title', 'Previous post link', 'twentythirteen' ) ); ?>
   <?php next_post_link( '%link', _x( '%title <span class="meta-nav">&rarr;</span>', 'Next post link', 'twentythirteen' ) ); ?>

So I tried just reversing their order, i.e.

   <?php next_post_link( '%link', _x( '%title <span class="meta-nav">&rarr;</span>', 'Next post link', 'twentythirteen' ) ); ?>
   <?php previous_post_link( '%link', _x( '<span class="meta-nav">&larr;</span> %title', 'Previous post link', 'twentythirteen' ) ); ?>

but surprisingly, that didn't change anything(!). I know I am getting into this function, because if I change some characters (like changing the &rarr to -->) that shows up. Iss there some funny CSS tricks going on here I'm not aware of?

BTW this is my first WordPress project, so I wouldn't be surprised if I'm missing something obvious.

1 Answer 1

1

You need to swap their arguments & rel tag too:

<?php echo str_replace( 'rel="next"', 'rel="prev"', get_next_post_link( '%link', _x( '<span class="meta-nav">&larr;</span> %title', 'Previous post link', 'twentythirteen' ) ) ); ?>
<?php echo str_replace( 'rel="prev"', 'rel="next"', get_previous_post_link( '%link', _x( '%title <span class="meta-nav">&rarr;</span>', 'Next post link', 'twentythirteen' ) ) ); ?>
3
  • Unfortunately, that didn't help any. Still displaying post #3 on the left, and post #1 on the right. The arguments mostly just specify whether the arrow appears to the left or right of the title. Otherwise they are identical, except for the "Previous post link" and "Next post link"; I don't know how they are used. Those two strings don't appear anywhere else in the code, so they are not being compared to anything.
    – tcrosley
    Nov 5, 2015 at 11:25
  • You're right - the functions output a rel=prev|next tag, which is probably what the CSS is targeting. You can edit the CSS, or swap the tags with string replace (see revision). Nov 5, 2015 at 11:35
  • That worked! I saw the rel tags when I dumped the page source, but I couldn't figure out how they worked in the CSS. Swapping them on the fly as the strings are returned from get_next_post_link and get_previous_post_link is brilliant. Thank you so much!
    – tcrosley
    Nov 5, 2015 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.