在 wordpress 的博客页面上显示博客图像的问题
issue in displaying blog image on blog page in wordpress
我在我的网站上有一个博客页面...有不同的 posts ...在左侧显示博客图像,在右侧写入文本..当我点击特定的博客,该 post 的主页显示为图像在顶部,文本在图像下方。
问题是在我的博客页面上没有显示左侧图像,而是显示默认图像.. bt 当我点击 post.. 那个特定 post 的主页有图像.. .
<div class="blog-img mainimg" style="">
<?php $blogmainimg = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );?>
<?php if($blogmainimg[0] == '') : ?>
<img src="<?php bloginfo('template_url')?>/images/Noimg.png" />
<?php else : ?>
<?php the_post_thumbnail(); ?>
<?php endif; ?>
</div>
只有 "if" 有效....其他无效
在博客页面上,所有 post 都有 NOIMG.png.. 这是错误的
???
让我们试试更简单的解决方案。这使用 has_post_thumbnail() 检查是否指定了特色图片,因为您确实不需要在提供的代码中使用 wp_get_attachment_image_src()。
<div class="blog-img mainimg" style="">
<?php if(has_post_thumbnail($post->ID)) : ?>
<?php the_post_thumbnail(); ?>
<?php else : ?>
<img src="<?php bloginfo('template_url')?>/images/Noimg.png" />
<?php endif; ?>
</div>
这使用 has_post_thumbnail() 来查看 post 是否指定了一个,如果有,它将显示它使用 the_post_thumbnail()。如果没有,它将恢复为默认值。
如果这不起作用,则可能是使用 the_post_thumbnail() 的问题,这主要取决于显示博客 post 的循环。如果是这样,试试这个:
<div class="blog-img mainimg" style="">
<?php if(has_post_thumbnail($post->ID)) : ?>
<?php echo get_the_post_thumbnail( $post->ID, 'single-post-thumbnail' ); ?>
<?php else : ?>
<img src="<?php bloginfo('template_url')?>/images/Noimg.png" />
<?php endif; ?>
</div>
如果这仍然不能解决问题,请post为您的页面添加循环,我可以进一步解决问题。
我在我的网站上有一个博客页面...有不同的 posts ...在左侧显示博客图像,在右侧写入文本..当我点击特定的博客,该 post 的主页显示为图像在顶部,文本在图像下方。 问题是在我的博客页面上没有显示左侧图像,而是显示默认图像.. bt 当我点击 post.. 那个特定 post 的主页有图像.. .
<div class="blog-img mainimg" style="">
<?php $blogmainimg = wp_get_attachment_image_src(get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );?>
<?php if($blogmainimg[0] == '') : ?>
<img src="<?php bloginfo('template_url')?>/images/Noimg.png" />
<?php else : ?>
<?php the_post_thumbnail(); ?>
<?php endif; ?>
</div>
只有 "if" 有效....其他无效 在博客页面上,所有 post 都有 NOIMG.png.. 这是错误的
???
让我们试试更简单的解决方案。这使用 has_post_thumbnail() 检查是否指定了特色图片,因为您确实不需要在提供的代码中使用 wp_get_attachment_image_src()。
<div class="blog-img mainimg" style="">
<?php if(has_post_thumbnail($post->ID)) : ?>
<?php the_post_thumbnail(); ?>
<?php else : ?>
<img src="<?php bloginfo('template_url')?>/images/Noimg.png" />
<?php endif; ?>
</div>
这使用 has_post_thumbnail() 来查看 post 是否指定了一个,如果有,它将显示它使用 the_post_thumbnail()。如果没有,它将恢复为默认值。
如果这不起作用,则可能是使用 the_post_thumbnail() 的问题,这主要取决于显示博客 post 的循环。如果是这样,试试这个:
<div class="blog-img mainimg" style="">
<?php if(has_post_thumbnail($post->ID)) : ?>
<?php echo get_the_post_thumbnail( $post->ID, 'single-post-thumbnail' ); ?>
<?php else : ?>
<img src="<?php bloginfo('template_url')?>/images/Noimg.png" />
<?php endif; ?>
</div>
如果这仍然不能解决问题,请post为您的页面添加循环,我可以进一步解决问题。