wordpress利用post推送文章至百度
wp
网站根目录下建 post.php
文件 并加入代码
<?
header('Content-Type:text/html;charset=utf-8');
$xmldata =file_get_contents("https://www.xiaohulizyw.cn/sitemap.xml");
$xmlstring = simplexml_load_string($xmldata,'SimpleXMLElement',LIBXML_NOCDATA);
$value_array = json_decode(json_encode($xmlstring),true);
$url = [];
for ($i =0;$i < count($value_array['url']);$i++){
echo $value_array['url'][$i]['loc']."<br/>";
$url[]= $value_array['url'][$i]['loc'];
}
$api ='百度推送链接';
$ch = curl_init();
$options = array(
CURLOPT_URL => $api,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => implode("
",$url),
CURLOPT_HTTPHEADER => array('Content-Type:text/plain'),
);
curl_setopt_array($ch, $options);
$result =curl_exec($ch);
echo $result;
使用
域名+/post.php