Need the Next and Previous arrow buttons, to show posts from the parent category page

I need the Next and Previous arrow buttons, to show posts from the parent category page, rather than random posts.

I created posts and added categories and tags to them.
Then added the category to the menu. I can see all the posts in that category, when i view the page and click on each one, which is great. However; from the post, when I click the previous/next arrow, it shows a random post rather than a post from the same category.

I read an article “https://theme.co/apex/forum/t/how-do-i-add-pagination-to-posts/8239/4”, which seems similar. However, the code is not in one place and so is confusing to me.

Can we achieve this without changing any code? In case any code modifications are needed, kindly mention exactly where to enter the code AS WELL. I am very new to word press and x theme.

Thanks in advance!

Hi there,

Depending on which stack you are using the code may differ. The code below is for the Integrity stack. You can check your stack by going to X > Launch > Options > Stacks and see which one is chosen.

This is a customization of the theme which is outside of our support scope, we will do our best to show you how to do so but we will not be able to implement or maintain the code in the future.

First of all, you will need to install a Child Theme. Then you need to add the code below at the end of the functions.php file in the Child Theme:

function x_entry_navigation() {

	$stack = x_get_stack();

	if ( $stack == 'integrity' ) {
		$left_icon  = '<i class="x-icon-chevron-left" data-x-icon=""></i>';
		$right_icon = '<i class="x-icon-chevron-right" data-x-icon=""></i>';
	} else {
		$left_icon  = '<i class="x-icon-arrow-left" data-x-icon=""></i>';
		$right_icon = '<i class="x-icon-arrow-right" data-x-icon=""></i>';
	}

	$is_ltr    = ! is_rtl();
	$prev_post = get_adjacent_post( true, '', false );
	$next_post = get_adjacent_post( true, '', true );
	$prev_icon = ( $is_ltr ) ? $left_icon : $right_icon;
	$next_icon = ( $is_ltr ) ? $right_icon : $left_icon;

	?>

	<div class="x-nav-articles">

		<?php if ( $prev_post ) : ?>
			<a href="<?php echo get_permalink( $prev_post ); ?>" title="<?php __( 'Previous Post', '__x__' ); ?>" class="prev">
				<?php echo $prev_icon; ?>
			</a>
		<?php endif; ?>

		<?php if ( $next_post ) : ?>
			<a href="<?php echo get_permalink( $next_post ); ?>" title="<?php __( 'Next Post', '__x__' ); ?>" class="next">
				<?php echo $next_icon; ?>
			</a>
		<?php endif; ?>

	</div>

	<?php

}

Thank you.

Thanks for fixing my issue yesterday :D, Christopher.

I am using Ethos Stack and already have a child theme installed [I thought installing a child theme was a best practice].

Have issues been reported after inserting this code? After upgrade does it cause issues?

So am I wrong in saying, that case X theme does not provide previous and next navigation feature on posts within a category?

Is there another way to achieve this? Would you suggest some third party plugins, instead?

When you say, “wont be able to support the code in the future”, If an issue occurs and if we remove that code…would you then support it?..Sorry I just got worried about this… All m trying to do is make a good user experience and providing prev and next i thought would be good.

Am using Ethos and again am new to this.

Hi there,

There should be no issues implementing this code, it’s a pluggable function which will replace the original, hence, will have no conflict with naming.

X does have previous/next navigation, and it’s where that code is pulled. You only need to add it to your child theme to replace the original (pluggable). Plus, that code already pulls the posts from its parent category, but if a post has multiple categories then it may display different posts when navigated.

Would you mind providing your site’s URL? I just like to see how it’s currently set up in your end.

And it’s not possible without changing the code since it’s part of the template, and only displayable through PHP code.

Thanks!

Hello Rad,

Sorry for the delay in replying.

Please find my details in the Secure Note.

Thanks Much

Hi There,

Yes, installing child theme is the best practice, especially if you’re planning to modify a Theme function (like what you want to do with the prev and next navigation.), I’d just tested the code on my dev site and there is no issue.

The previous and next navigation will show you a chronological order of posts regardless of its category, this is why we need to modify the function to show posts within a category only.

There might be a 3rd party that does what you need, but regretfully we have not tested those plugins and can’t suggest any of those, with that said if you want to go in this route you need to test the plugin on your own. (WP previous and next Post Navigation)

Yes, there are cases that modified functions won’t work in the future (latest versions) because of the code changes, when this happens you need to edit your modified function on the child theme to follow the changes made, or if the modified function is causing an issue on the site then simply remove it.

You can add this to Theme Options > CSS

.archive .x-header-landmark {display: none;}

Or you can give the category a title so it does not show the generic “Category Archive” title. To do this, navigate to Posts > Categories, edit the desired category and look for the Archive Title field.

Please clarify what is wrong with breadcrumbs.

Yes, and we need to modify a template to achieve this. Please create a new thread for this.

Can you confirm that the CATEGORY IDS you entered in the field are correct?

Please add this to Theme Options > CSS

.x-colophon.bottom .x-colophon-content,
.x-colophon.bottom .x-colophon-content a {
	color: #fff;
}

Hope it helps,
Cheers!

Hello Friech,

I am new to word press and X theme.

Could you please direct me to where the functions.php file of the child theme is located. I checked in plugins ->editor from the Word Press interface and couldn’t find it.

Also, since i am using Ethos, should i just replace “integrity” with “ethos” within the above mentioned code?

About the breadcrumb Query-> it displays “Blog” and then the name of the post. I don’t have any page called ‘blog’. I would expect it to display the category name. But i think, this should be fixed after the functions code had been modified.

Thanks in Advance!

The code works but how about an ‘infinite’ next/prev links – the previous button/link on first post will link to the last post and vise versa?

Could you please tell me where this file is located

Hi there,

The file is in the Root folder of your child theme. If you want you can access the functions.php file using FTO which you need to get the information from your hosting service provider:

wp-content/themes/x-child

Usually, if your hosting service provider allows you can go to Appearance > Editor and click on the Theme Functions option and the content of the functions.php the file will be available for you to edit:

You can change integrity to ethos in the code. Thank you.

1 Like

Thank you so much Christopher, it worked ! :gift: :grin:

Glad to hear it :slight_smile: Cheers!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.