外贸营销
wordpress检测当前页面百度是否收录
对于新上线网站总会去查询网页收录了多少,哪些还没收录。这个功能实用性极佳。打开文章直接显示网页是否被百度收录,没有收录可以直接点击提交给百度。
<pre>//百度收录提示if(git_get_option('git_baidurecord_b') && function_exists('curl_init')):function baidu_check($url) {global $wpdb;$post_id = (null === $post_id) ? get_the_ID() : $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, '没有找到')) {if ($baidu_record == 0) {update_post_meta($post_id, 'baidu_record', 1);} else {add_post_meta($post_id, 'baidu_record', 1, true);}return 1;} else {if ($baidu_record == false) {add_post_meta($post_id, 'baidu_record', 0, true);}return 0;}} else {return 1;}}function baidu_record() {if (baidu_check(get_permalink()) == 1) {echo '<a title="" href="http://www.baidu.com/s?wd=' . get_the_title() . '" target="_blank"rel="external nofollow" data-original-title="点击查看">已收录</a>';} else {echo '<a title="" href="http://zhanzhang.baidu.com/sitesubmit/index?sitename=' . get_permalink() . '" target="_blank"rel="external nofollow" data-original-title="点击提交,谢谢您!">未收录</a>';}}endif;</pre>
上面的函数式放在functions文件中,然后在文章内容页面适合地方加入下方这段代码
<pre><?phpif (git_get_option('git_baidurecord_b') && function_exists('curl_init')) { ?><span class="muted"><i class="fa fa-flag"></i> <?phpbaidu_record(); ?></span></pre>
标签