最新消息: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)

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

matteradmin9PV0评论

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!

Post a comment

comment list (0)

  1. No comments so far