categories - Excluding category from post navigation in Wordpress?

admin2025-05-31  0

I'm looking to exclude a category from the post navigation. Originally, I looked up manipulating <?php the_post_navigation(); ?> to exclude categories, but a few posts I read (like this) pointed me towards using <?php previous_post_link(); ?> and <?php next_post_link(); ?> instead.

Here's what I've put together so far:

<div class="left col-6">
    <h5>Previous Post</h5>
        <small><?php previous_post_link('%link', '%title', $excluded_terms); ?> </small>
</div>
<div class="right col-6 text-right">
    <h5>Next Post</h5>
    <small><?php next_post_link('%link', '%title', $excluded_terms); ?> </small>
</div>

With $excluded_terms = '463';

The problem I'm running into is that this only cycles through ONE post category and excludes posts from this ONE category that are also in category 463. I'm trying to cycle through ALL post categories except category 463. Thoughts?

Thanks in advance!

I'm looking to exclude a category from the post navigation. Originally, I looked up manipulating <?php the_post_navigation(); ?> to exclude categories, but a few posts I read (like this) pointed me towards using <?php previous_post_link(); ?> and <?php next_post_link(); ?> instead.

Here's what I've put together so far:

<div class="left col-6">
    <h5>Previous Post</h5>
        <small><?php previous_post_link('%link', '%title', $excluded_terms); ?> </small>
</div>
<div class="right col-6 text-right">
    <h5>Next Post</h5>
    <small><?php next_post_link('%link', '%title', $excluded_terms); ?> </small>
</div>

With $excluded_terms = '463';

The problem I'm running into is that this only cycles through ONE post category and excludes posts from this ONE category that are also in category 463. I'm trying to cycle through ALL post categories except category 463. Thoughts?

Thanks in advance!

Share Improve this question asked Jun 26, 2018 at 18:18 Brittany Layne RaphealBrittany Layne Rapheal 1013 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Check the signature of the function:

next_post_link( string $format = '%link &raquo;', string $link = '%title', bool $in_same_term = false, array|string $excluded_terms = '', string $taxonomy = 'category' );

Excluded terms should be the fourth argument. Your code is passing a "true-ish" argument to $in_same_term.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748633653a313672.html

最新回复(0)