在WordPress中使用后缩略图显示最新帖子



我试图通过网站的博客详细信息页面的侧边栏上的缩略图,标题和作者姓名显示最新帖子。标题和作者是正确的,但缩略图映像不正确,而且当我在查看源中选中时,它没有采用缩略图150*150,它的原始尺寸为原始大小。

检查URL: - https://stageserver.co/officework/dev/6-lead-generation-techniques-to-immed-ther-mymed-turn-your-business-into-ainto-a-a-a-sales-magnet-9-3/

这是我尝试的代码: -

<!-- Latest News -->
                    <?php $orig_post = $post;
   global $post;
   $tags = wp_get_post_tags($post->ID);
  if ($tags) {
  $tag_ids = array();
  foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
  $args=array(
  'tag__in' => $tag_ids,
  'post__not_in' => array($post->ID),
  'posts_per_page'=>5, // Number of related posts that will be shown.
  'caller_get_posts'=>1
  );
  $my_query = new wp_query( $args );
  if( $my_query->have_posts() ) {
   echo '<div class="sidebar-widget latest-news"><div class="sidebar-title">
                            <h2>Recent Post</h2>
                        </div>';
  while( $my_query->have_posts() ) {
  $my_query->the_post(); ?>
 <div class="widget-content">
 <article class="post">
 <div class="post-thumb">
    <a href="<?php the_permalink(); ?>" ><img src="<?php 
     the_post_thumbnail(); ?>" ></img></a>
</div>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<div class="post-info"><?php the_author(); ?></div>
 </article>
 </div>
 <? }
echo '</div>';
 }
 }
 $post = $orig_post;
 wp_reset_query(); ?>

预先感谢PLS尽快提供帮助,我是PHP

的新手

您可以将大小和其他属性传递给the_post_thumbnail($ size,$ attr(;函数,默认值:" thumbnail"。

尝试:

the_post_thumbnail('thumbnail');

the_post_thumbnail('thumbnail'); // Thumbnail (default 150px x 150px max)
the_post_thumbnail('medium'); // Medium resolution (default 300px x 300px max)
the_post_thumbnail('medium_large'); // Medium Large resolution (default 768px x 0px max)
the_post_thumbnail('large'); // Large resolution (default 1024px x 1024px max)
the_post_thumbnail('full'); // Original image resolution (unmodified)
the_post_thumbnail( array(100,100) ); // Other resolutions

好的,也要the_post_thumbnail((不仅返回图像,因此请尝试:

<div class="post-thumb">
    <a href="<?php the_permalink(); ?>">
        <?php the_post_thumbnail('thumbnail'); ?>" >
    </a>
</div>

最新更新