1、打开当前使用的主题模板的functions.php文件,在文件的最后添加如下代码:
2、global $post, $posts;$first_img = ”;ob_start();ob_end_clean();$output = preg_match_all(‘//i’, $post->post_content, $matches);$first_img = $matches [1] [0];if(empty($first_img)){ //Defines a default image$first_img = “/wp-content/themes/****/images/default.jpg”;}return $first_img;} ?>
3、打开当前使用的主题模板的index.php文件,在你想要显示的合适位置,添加如下代码:
4、[img src="" alt="" title="" width="578px" height="188px" /]
5、将代码中的[]修改成<>即可
6、实现的功能是,当你的文章有图片的话,在首页自动截取文章的第一张图片显示,如果文章没有图片,在首页显示默认的default.jpg。最后找张你喜欢的default.jpg,上传到主题模板的images目录即可。