$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>loop - Next Posts Prev Posts for Standard post format only|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

loop - Next Posts Prev Posts for Standard post format only

matteradmin9PV0评论

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'
            );
Post a comment

comment list (0)

  1. No comments so far