WordPress 百度主动推送全部链接

我站点收录好低啊,参考百度搜索资源平台的Api写了个简单的自动推送全部链接。代码如下:

<?php $urls = array(); require('./wp-blog-header.php'); header('HTTP/1.1 200 OK'); $posts_to_show = 99999; // 获取文章数量 array_push($urls, 'https://'.$_SERVER['HTTP_HOST']); /* 文章页面 */ $myposts = get_posts( "numberposts=" . $posts_to_show ); foreach( $myposts as $post ) { array_push($urls, get_permalink($post->ID));
}
/* 单页面 */
$mypages = get_pages();
if(count($mypages) > 0) {
foreach($mypages as $page) {
 array_push($urls, get_page_link($page->ID));
}
}
/* 博客分类 */
$terms = get_terms('category', 'orderby=name&hide_empty=0' );
$count = count($terms);
if($count > 0){
foreach ($terms as $term) {
 array_push($urls, get_term_link($term, $term->slug));
}
}
/* 标签(可选) */
$tags = get_terms("post_tag");
foreach ( $tags as $key => $tag ) {
 $link = get_term_link( intval($tag->term_id), "post_tag" );
 if ( is_wp_error( $link ) ) {
 return false;
 $tags[ $key ]->link = $link;
 }
 array_push($urls, $link);
}
$api = '修改为你的接口调用地址';
$ch = curl_init();
$options =  array(
    CURLOPT_URL => $api,
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POSTFIELDS => implode("n", $urls),
    CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
echo $result

代码在WP根目录放置。修改$api为你资源平台的接口调用地址 。建议写个复杂一点的文件名,比如haoziblogbaidutuisong.php,避免给别人猜到。然后添加一个定时任务,每天监控一次就可以了,效果如下图:

赞(0) 打赏
转载请保留出处:耗子博客 » WordPress 百度主动推送全部链接
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

金额随意,一百两百也不介意的啦

支付宝扫一扫打赏

微信扫一扫打赏

Loading