Site logo

Archived topic

Need category single post next/prev navigation when category is sorted by title

5 replies · Started by Denise on February 21, 2018

Viewing posts 1–6 of 6

Hello GP Friends,

I would like site visitors to have the ability to browse the individual posts by category, sorted by post title.

Objectives:
-- All queries in the site are sorted by Post Title, ascending (and never by date)
-- All posts have just one category
-- When the user goes to a single post page, the navigation for previous/next posts stays within the category for that post. The previous/next will be sorted by Title

QUESTION:
How can I change the single post navigation to follow the post's category loop, sorted by Title?

I am currently using two code snippets.
The first is to stay within the category.
The second is to order queries by title.

add_action( 'after_setup_theme', 'mdp_category_specific_post_navigation' );
function mdp_category_specific_post_navigation() {
add_filter( 'generate_category_post_navigation', '__return_true' );
}

add_action( 'pre_get_posts', 'mdp_modify_query_order' );
function mdp_modify_query_order( $query ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
}

Many thanks,
Denise

(question updated and clarified on 2/22/2018 at 4:35 CST)

Wow, thanks so much for this help, Tom. I'll have some time to work on the site this weekend and let you know.

As always, working with GeneratePress is such a delight. I look forward to this project a lot more since I switched to using your theme =)

Best wishes,
Denise

No problem! I hope it helps! :)

Thanks, Tom. That's what I was looking for. I'd rather not have to include an extra plugin so I'll try and write the code myself, based on this one.

You may close this ticket.

Best wishes,
Denise

Glad I could help :)

This archived topic is closed to new replies.