0

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.

1 Answer 1

1

It seems like, you have added permalink for categories inside span tag. Where do you want to add permalink actually?

If you want to apply permalink for post title, then add permalink inside <h4> tag. currently your href is empty inside <h4> element.

<h4 class="post-title">
    <a href="<?php echo get_the_permalink() ?>"><?php the_title(); ?> </a>
</h4>
1
  • Wow I really am blind. Thanks for your time and help!
    – Pbalazs89
    Commented Jan 10, 2023 at 8:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.