简体   繁体   English

WordPress:如果设置后使用缩略图?

[英]wordpress: use post-thumbnail if set?

hey guys, i hope there are a few wordpress experts out there that can help me with ths. 大家好,我希望有一些Wordpress专家可以为我提供帮助。 i'm using: 我正在使用:

the_post_thumbnail('medium');

to view a post-thumbnail that can be set for every post in the backend. 查看可以为后端中的每个帖子设置的缩略图。

however, if there is no postthumbnail set i want to print out a different image. 但是,如果没有设置缩略图后,我想打印出不同的图像。 any idea how i can check the function to find out if a post-thumbnail for a specific post is set? 任何想法,我怎么可以检查功能,以找出是否设置了特定职位的缩略图?

thank you 谢谢

<?php if( get_post_thumbnail_id() ):
    the_post_thumbnail( 'medium' );
else: ?>
    <img src="some_other_image.png" alt="" />
<?php endif; ?>

The above code will work fine, Though i think the write way would to show your post would be like this: 上面的代码可以正常工作,尽管我认为写方法来显示您的帖子会像这样:

// Wrap it
if  ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) {
    the_post_thumbnail( 'medium' );
} else {
    // If there is no thumb, show a default one.
    echo '<img src="'.get_bloginfo("template_url").'/images/default-post-thumbnail.gif" alt="" />';
}

Not much difference, just the wrapper. 区别不大,只是包装纸。

Source: How to use Post Thumbnails Feature in Wordpress! 来源: 如何在Wordpress中使用“发布缩略图”功能!

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

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