Warning: Undefined variable $ex_word in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 133
Warning: Undefined variable $case in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 133
Warning: Undefined variable $ex_word in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 134
Warning: Undefined variable $case in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 134
Warning: Undefined variable $case in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 136
Warning: Undefined variable $ex_word in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 138
Warning: Undefined variable $ex_word in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 133
Warning: Undefined variable $case in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 133
Warning: Undefined variable $ex_word in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 134
Warning: Undefined variable $case in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 134
Warning: Undefined variable $case in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 136
Warning: Undefined variable $ex_word in /www/wwwroot/yunfuwuqi.chinazhx.cn/wp-content/themes/lsw_FB6LDT/lsw/functions.php on line 138
很多时候我们在写文章的时候, 一些文章是没有图片的那么对于现在搜索引擎来说, 没有图片的文章对于seo并不是很友好, 那么我们可以判断文章内有图片就给文章添加一张图片, 如何添加跟着卡卡哥一起来了解下吧.
实现的方法还是比较的简单, 需要函数代码来实现, 把下面的这个代码添加到functions函数模板里面
//文章判断图片 add_filter('the_content','isimages','p'); //判断文章是否有图片 function isimages($content) { if( !is_page() ){ global $post; $temp_url = ""; if ( has_post_thumbnail() ) { } else { $content = $post->post_content; $id = $post->ID; preg_match_all('/<img.*?(?: |\\t|\\r|\\n)?src=[\'"]?(.+?)[\'"]?(?:(?: |\\t|\\r|\\n)+.*?)?>/sim', $content, $strResult, PREG_PATTERN_ORDER); $n = count($strResult[1]); if($n > 0){ }else { $temp_no = rand(1,51); $temp_url = "<img src='".get_bloginfo('url')."/images/".$temp_no.".jpg' alt='".$post->post_title."'>"; $content = $temp_url . $content; $my_post = array(); $my_post['ID'] = $id; $my_post['post_content'] = $content; wp_update_post( $my_post ); } } } return $content; }
这个是在文章的顶部添加一张图片, 还有就是卡卡哥自己添加了一个P标签, <img src='”.get_bloginfo(‘url’).”/images/这里的图片地址是可以更改的, 默认的是在根目录的images文件下默认的1-51张图片随机调用, 等你调用后刷新是不会变动的.
其实还是主要是为了用户阅读更加的友好, 还有搜索引擎的友好, 我们在添加的时候可以根据的要求来添加.