简体   繁体   English

在WordPress的博客页面上显示博客图像的问题

[英]issue in displaying blog image on blog page in wordpress

i am having a blog page in my website... There are different posts ... on left side blog image is displayed , on right side text is written..when i click on particular blog, the main page of that post appears with image on the top and text down the image. 我在我的网站上有一个博客页面...有不同的帖子...在左侧显示博客图像,在右侧写文本..当我单击特定博客时,该帖子的主页显示为图片在顶部,文字在图片下方。 The issue is that on my blog page the left side images are not displayed rather default image is displayed.. bt when i click on post.. the main page of that particular post is having image... 问题是,在我的博客页面上没有显示左侧图像,而是显示了默认图像。.bt,当我单击帖子时..该特定帖子的主页上有图像...

 <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> 

only "if" is working.... else is not working on blog page, all the posts are having NOIMG.png.. which is wrong 只有“如果”在工作。...其他在博客页面上不工作,则所有帖子都具有NOIMG.png ..这是错误的

??? ???

Let's try a more simplified solution. 让我们尝试一个更简化的解决方案。 This uses the has_post_thumbnail() to check if a featured image is specified, since you really do not need to utilize the wp_get_attachment_image_src() in the provided code. 这使用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>

This uses has_post_thumbnail() to see if the post has one specified, if it does, it will display it uses the_post_thumbnail(). 它使用has_post_thumbnail()查看帖子是否已指定,如果指定了,它将使用the_post_thumbnail()显示。 If not, it will revert to the default. 如果不是,它将恢复为默认值。

If this doesn't work, than it could be an issue of using the_post_thumbnail(), this would mostly depend on your loop that's displaying the blog posts. 如果这不起作用,那么使用the_post_thumbnail()可能是一个问题,这主要取决于显示博客文章的循环。 If that is the case, try this: 如果是这种情况,请尝试以下操作:

<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>

If this still does not solve the issue, please post the loop for your page as well, and I can further troubleshoot it. 如果仍然不能解决问题,请也为您的页面发布循环,我们可以对其进行进一步的故障排除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM