I'm not sure how to word this one at all so suggestions welcome. I'm using this code in functions.php to output a list of posts with anchors on archive.php and home.php
function output_link() {
// this outputs an external custom url for the 'resource' post type
if (is_post_type_archive( 'resources' )) {
return 'https://' . get_field('website');
}
return get_the_permalink();
}
home.php (blog archive)
<div class="blog-container">
<?php
if (have_posts()):
while (have_posts()):
?>
<div class="card container">
<a href="<?= output_link();?>">
<div class="card-body row"><?php
the_post();
?>
<div class="col-sm img-fluid post-image"><?php
the_post_thumbnail('medium');
?></div>
<div class="col-sm p-2 m-0">
<h2 class="card-title text-center"><?php the_title();?></h2>
</a>
<p class="card-text"><?php the_excerpt();?></p>
</div>
</div> <!-- card body -->
</div><!-- card -->
<?php
endwhile;
endif;
?>
</div>
when I click on any post link in the blog, or the 'programmes' or 'events' CPTs it takes you not to the post you clicked on, but the following one.
Example: The link for 'Post 1' leads to 'Post 2', the link for 'Post 2' leads to 'Post 3', and so on... While the last post in the list works normally, i.e 'Post 4' leads to 'Post 4'
Any idea what's causing this?
Thanks!
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745604830a4635612.html
评论列表(0条)