loop - Next Posts Prev Posts for Standard post format only

admin2025-06-04  4

I am using the following functions in my single.php file to display links to Previous and Next posts:

get_next_post();
get_previous_post();

I store them in 2 variables:

$next_post = get_next_post();
$prev_post = get_previous_post();

and outputting them at the bottom of the page using get_permalink:

$next_post_url = get_permalink( $next_post->ID );
<a href="<?php echo $next_post_url; ?>"> Next </a>

and

$prev_post_url = get_permalink( $prev_post->ID );
<a href="<?php echo $prev_post_url; ?>"> Previous </a>

It does work fine and gives me the "previous" and "next" posts However, it includes all the posts in my blog including all post formats: gallery, images, quote, aside etc etc

Id like to exclude them from being included in the loop because they don't have content. their only purpose in my blog is to show quote or image or something else but the only "content" post which is important is the standard post format

Anyone knows how to accomplish that using my code? (preferably) or different code is better

Thanks

I am using the following functions in my single.php file to display links to Previous and Next posts:

get_next_post();
get_previous_post();

I store them in 2 variables:

$next_post = get_next_post();
$prev_post = get_previous_post();

and outputting them at the bottom of the page using get_permalink:

$next_post_url = get_permalink( $next_post->ID );
<a href="<?php echo $next_post_url; ?>"> Next </a>

and

$prev_post_url = get_permalink( $prev_post->ID );
<a href="<?php echo $prev_post_url; ?>"> Previous </a>

It does work fine and gives me the "previous" and "next" posts However, it includes all the posts in my blog including all post formats: gallery, images, quote, aside etc etc

Id like to exclude them from being included in the loop because they don't have content. their only purpose in my blog is to show quote or image or something else but the only "content" post which is important is the standard post format

Anyone knows how to accomplish that using my code? (preferably) or different code is better

Thanks

Share Improve this question asked Oct 5, 2016 at 13:54 gil hamergil hamer 6713 gold badges21 silver badges37 bronze badges 2
  • To stop this (it includes all the posts) from happening you need to make different category for posts that are need to show in pagination. Then in loop you can show only that category of posts. Lets assume your post's category ID is 5. Use 'cat'=> 5 in your array. – Rishabh Commented Oct 6, 2016 at 5:09
  • Thanks @Rishabh but that I know. I am looking for a better way without having to add category there must be a way to filter post formats Thanks – gil hamer Commented Oct 6, 2016 at 7:02
Add a comment  | 

1 Answer 1

Reset to default 0
previous_post_link(
                '<div class="text-center video-text-btn"> %link </div> ', 
                'pre', 
                $in_same_term = true, 
                $excluded_terms = 'Standard-post-format-name', 
                $taxonomy = 'post_format'
            );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748978168a315330.html

最新回复(0)