如何在wordpress中将帖子链接添加到缩略图


How to add post link to thumbnail in wordpress?

我在index.php中使用以下循环来显示带有缩略图的帖子:

<main id="main">
            
                <?php 
                // the query
                $args = array('posts_per_page' => 10 );
                $the_query = new WP_Query( $args ); 
            
                ?>
            
                <?php if ( $the_query->have_posts() ) { ?>
            
                    <!-- loop -->
            
                    <?php while ( $the_query->have_posts() ) {
                     
                                $the_query->the_post(); ?>
           <article id="post"> 
                  
                        <div id="thumbnail">
                        
                            <?php
                            if ( has_post_thumbnail() ) { ?>
                                 <?php the_post_thumbnail(); } ?>
                    </div>
                   
                   <h2><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h2>
                   
                   <div class="entry">
                   
                        <?php the_excerpt(); ?>
                        
                   </div>
                 
           
           </article>
           
	
    
                <?php } } else { ?>
                <p><?php _e( 'Die Posts entsprechen nicht den Kriterien.' ); ?></p>
                <?php }  ?>
    			
               <!-- end of the loop -->
	
    
               <?php wp_reset_postdata(); ?>
        </main>
    

如何向缩略图添加永久链接?当用户点击它时,他应该被引导到帖子。目前,什么都没有发生。

谢谢你的回答。

编辑:我添加了整个循环,因为Deepti的回答产生了一个错误。也许有人可以帮我。

<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
    <?php the_post_thumbnail(); ?>
</a>
<?php endif; ?>