permalinks - CPT links error: each one links to next one further along in the list

I'm not sure how to word this one at all so suggestions welcome. I'm using this code in functions.php to outpu

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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信