wp query – The permalink redirecting to current article on single.php page

Question

My question refers to single.php.
On this page, I have a sidebar, and this sidebar displays the 6 latest posts.

However, when I visit the page, the information displayed is correct for these 6 posts, aside from the permalink.

Here’s the code:

<div id="secondary" class="col-lg-3">
<div class="post-list-item widgets">
    <?php get_template_part( 'template-parts/ads/cikkek', 'oldalsav-felso' ); ?>
    <div class="tab-content">
        <div role="tabpanel" class="tab-pane active ts-grid-box post-tab-list" id="home">

            <?php
            wp_reset_query();
            $args = array(
            'posts_per_page' => 6,
            'post_type' => 'post',
            );
            $wp_querysidebar = new WP_Query( $args );
            $i = 0; 
            if ( $wp_querysidebar->have_posts() ) {
                while ( $wp_querysidebar->have_posts() ) {
                    $wp_querysidebar->the_post();
            $i++;
            $categories = get_the_category();
            
                ?>

            <div class="post-content media">
                <img class="d-flex sidebar-img"
                    src="<?php echo get_the_post_thumbnail_url($post->ID, 'homethumbnails');?>" alt="">
                <div class="media-body">
                    <span class="post-tag">
                        <a href="<?php the_permalink(); ?>" class="
                        <?php if ($i == 1) {
                           echo "green-color";
                        }?>

                        <?php if ($i == 2) {
                           echo "yellow-color";
                        }?>

                    <?php if ($i == 3) {
                           echo "blue-color";
                        }?>

                    <?php if ($i == 4) {
                           echo "pink-color";
                        }?>

                    <?php if ($i == 5) {
                           echo "yellow-color";
                        }?>

                        "> <?php 
                    if ( ! empty( $categories ) ) {
                        echo esc_html( $categories[0]->name );  
                    } ?></a>

                    </span>

                    <h4 class="post-title">
                        <a href=""><?php the_title();?> </a>
                    </h4>
                </div>
            </div>

            <?php }} wp_reset_postdata(  ); ?>
        </div>
        <div class="container mt-2">

            <?php echo wp_tag_cloud(); ?>

        </div>
    </div>
</div>

I tried resetting the query. I tried adding $post->ID to the_permalink(), but I don’t understand why the loop would provide all the correct information for the posts, except for the permalink.

0
Pbalazs89 4 weeks 2023-01-09T03:05:07-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse