-
AuthorPosts
-
February 20, 2019 at 11:26 pm #1069729
Hi,
I am trying to replicate the funtion of this site: https://www.iflymagazine.com/en/magazines With a bit of research, and added snippet to the function.php file to link to the most recent Post within a category, I have gotten pretty darn close.
The one issue I have…and my question…once I link to the most recent post within a specific category the Post Navigation then takes the user outside of the selected category and simply displays the next/previous Post regardless of category. How can I have the next/previous arrows only show the selected category?
Thanks,
SladeFebruary 24, 2019 at 9:01 pm #1071026Hey Slade,
What is the code you have used?
Best regards,
BasilisFebruary 24, 2019 at 11:42 pm #1071048Hey Basilis,
Here is the code placed in the child-theme function.php file:
function wpa_latest_in_category_redirect( $request ){ if( isset( $_GET['latest'] ) && isset( $request->query_vars['category_name'] ) ){ $latest = new WP_Query( array( 'category_name' => $request->query_vars['category_name'], 'posts_per_page' => 1 ) ); if( $latest->have_posts() ){ wp_redirect( get_permalink( $latest->post->ID ) ); exit; } } } add_action( 'parse_request', 'wpa_latest_in_category_redirect' );
Example (this is a staging website so you will need to login: username: flywheel pass: sg3Jumpstart1)
Now you can use a link such as https://staging.hushed-drink.flywheelsites.com/category/blog/?latest which takes the user to the post category “blog” and shows the most recent post in that category.My question is…once you get to the ‘most recent post’ how do you make the next/previous navigation arrows stay within the blog category? Currently they just navigate to the next Post (regardless of category) in line of date plubished.
February 27, 2019 at 2:53 pm #1072291Hi,
Thanks for the update.
Use the “avia_post_nav_settings” to set the post navigation to retrieve posts from the same category.
add_filter('avia_post_nav_settings', 'avia_post_nav_settings_mod'); function avia_post_nav_settings_mod($settings) { $settings['same_category'] = true; return $settings; }
Please add it in the functions.php file
Best regards,
IsmaelFebruary 28, 2019 at 6:53 am #1072505Holy Smokes!! That is brilliant! Works perfect! Thank you so much Ismael!!!
March 1, 2019 at 4:29 am #1072852 -
AuthorPosts
- The topic ‘Post Navigation arrows only show specific Post Category’ is closed to new replies.