//开启缩略图
if ( function_exists('add_theme_support') ) add_theme_support('post-thumbnails'); //开启缩略图
//缩略图调用方法一
function get_content_first_image($content){
if ( $content === false ) $content = get_the_content();
preg_match_all('|<img.*?src=[\'"](.*?)[\'"].*?>|i', $content, $images);
if($images){
return $images[1][0];
}else{
return false;
}
}
在做东莞微商分销系统官网的时候,文章列表需要自动获取第一张图做缩略图,通过在wordpress主题function.php添加以上代码即可实现。