我的WordPress网站使用第一图像后缩略图,代码:默认的缩略图
add_filter('the_content','replace_content');
function get_first_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)) {
$first_img = "/path/to/default.png";
}
return $first_img;
}
有些岗位在内容上没有图像,所以我想用不同的默认缩略图它们:职位A类使用图片1,在cagory B在使用产品组别的职位...
我怎样才能做到这一点? 谢谢
感谢,让我试试我用first_image我的网站 –