Css 如果在wordpress上发布图像,如何隐藏特征图像
如果帖子内容中没有媒体,我想显示特色图片。我尝试了以下方法,但不起作用:Css 如果在wordpress上发布图像,如何隐藏特征图像,css,wordpress,image,Css,Wordpress,Image,如果帖子内容中没有媒体,我想显示特色图片。我尝试了以下方法,但不起作用: .has-post-thumbnail .entry-featured-media.entry-featured-media-main { display:none } 我怀疑这只能通过css实现。 找到了类似问题的答案 试试这个: add-in functions.php: function catch_that_image() { global $post, $posts; $first_img =
.has-post-thumbnail .entry-featured-media.entry-featured-media-main {
display:none
}
我怀疑这只能通过css实现。 找到了类似问题的答案 试试这个: add-in functions.php:
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = "/images/default.jpg";
}
return $first_img;
}
此(if(!catch_that_image())
)将检查帖子内容中是否没有图像
if (!catch_that_image()) {
if ( has_post_thumbnail()) {
the_post_thumbnail();
}
}