我正在尝试在网站的博客详细信息页面的侧边栏中显示带有缩略图,标题和作者姓名的最新帖子。标题和作者是正确的,但是以某种方式缩略图不能正确显示,而且当我查看视图源时,缩略图的尺寸不是150 * 150,而是图像的原始尺寸。
这是我尝试过的代码:-
<!-- 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(); ?>
提前感谢您的帮助,请尽快我是php新手
答案 0 :(得分:0)
您可以将size和其他属性传递给the_post_thumbnail($ size,$ attr);函数,默认值:“缩略图后”。
尝试:
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()也会返回图像而不仅仅是URL,所以请尝试:
<div class="post-thumb">
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail('thumbnail'); ?>" >
</a>
</div>