最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin9浏览0评论

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!

发布评论

评论列表(0)

  1. 暂无评论