修改的文件主要有两个functions.php与single.php,大家可以在修改之前备份一下文件,以防止因操作不当引起的种种问题。
首先我们需要将一下代码添加到你主题的functions.php文件中,部分主题可能禁止编辑这个文件,不过主题作者应该会提供另一个文件方便大家对主题的修改,比如functions_z.php
- function baidu_check($url,$post_id){
- $baidu_record = get_post_meta($post_id,'baidu_record',true);
- if( $baidu_record != 1){
- $url='http://www.baidu.com/s?wd='.$url;
- $curl=curl_init();
- curl_setopt($curl,CURLOPT_URL,$url);
- curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
- $rs=curl_exec($curl);
- curl_close($curl);
- if(!strpos($rs,'没有找到该URL。您可以直接访问') && !strpos($rs,'很抱歉,没有找到与') ){
- update_post_meta($post_id, 'baidu_record', 1) || add_post_meta($post_id, 'baidu_record', 1, true);
- return 1;
- } else {
- return 0;
- }
- } else {
- r