Hello
I am having this little issue I am trying to resolve but I couldn't find a solution anywhere on the net so I am seeking my luck here.
I am using the following functions in my <strong>single.php</strong> 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 "<strong>previous</strong>" and "<strong>next</strong>" posts However, it includes all the posts in my blog including all post formats: gallery, images, quote, aside etc etc
<strong>(I don't want to include all my post formats. ONLY the standard posts)
</strong>
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 <strong>standard </strong>post format
I read the Posts Formats are like Taxonomy but I couldn't exclude them using the basic wordpress functions and excluding taxonomies
Anyone knows how to accomplish that using my code? (preferably) or different code is better
Thanks
Reigel Gallarde answers:
have you tried something like this??
if (!empty( $next_post )) {
$format = get_post_format() ? : 'standard';
if ($format == 'standard' ) {
$next_post_url = get_permalink( $next_post->ID );
<a href="<?php echo $next_post_url; ?>"> Next </a>
}
}
same thing with your $prev_post
hamergil comments:
That's very close but not perfect
I tried to use it but still if I am in "standard" post and I check the "next" and "previous"
at the bottom
the "previous" still gives me a link to the previous post regardless of it's format.
I need to ignore all formats in the Previous/Next loop except for the standard formts
so basically all other formats are hidden from this Next/Previous loop
See my file attached woth the original single.php
see if it helps
Thanks