Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress: previous_post_link / next_post_link by alphabetical order?

I'm developing a wordpress website with custom posts which are ordered alphabetically in the loop.

<!-- THE ARGS -->
<?php global $query_string;
$args = wp_parse_args($query_string);
$args = array(
    'post_type' => 'custom_post',
    'orderby' => 'title',
    'order' => 'ASC',
    'posts_per_page' => -1,
    ); ?>

<!--  THE LOOP -->
<?php $wp_query = new WP_Query( $args ); ?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<?php endwhile; ?>
<?php wp_reset_query(); ?>

Nothing fancy there, just a normal loop.

When I open a post, in its page I have the usual previous_post_link and next_post_link so I can navigate through posts. However, this is done by chronological order of the posts, and I wish to do so by the same alphabetical order as I used in the loop, of course. Any help on this matter would be very appreciated. Thanks in advance!

like image 469
Cthulhu Avatar asked Mar 29 '12 12:03

Cthulhu


1 Answers

It looks like this plug-in does what you're after, e.g.:

<ul class="pager">
        <?php previous_post_link_plus( array('order_by' => 'post_title') ); ?>
        <?php next_post_link_plus( array('order_by' => 'post_title') ); ?>
</ul>
like image 93
phillipadsmith Avatar answered Sep 17 '22 14:09

phillipadsmith