php代码获取WordPress网站所有的文章链接
1、网站根目录新建geturl.php
文件,将代全部码粘贴通过浏览器访问该文件即可(例如:域名/geturl.php
)
代码:
<?php
include ( "wp-config.php" ) ;
require_once (ABSPATH.'wp-blog-header.php');
global $wpdb;
$qianzui = "http://xxx.cn/";//网站域名
$houzui = ".html";//文章后缀
$sql="SELECT ID FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY ID DESC ";
$myrows = $wpdb->get_results($sql);
foreach ($myrows as $b) {
echo $qianzui;
echo $b->ID;
echo $houzui."<br/>";
}
?>
如果你的是ID的话(就是你的文章链接是这样的 https://www.xiaohulizyw.com/?p=520
)就使用这个代码:
<?php
include ( "wp-config.php" ) ;
require_once (ABSPATH.'wp-blog-header.php');
global $wpdb;
$sql="SELECT guid FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY ID DESC ";
$myrows = $wpdb->get_results($sql);
foreach ($myrows as $b) {
echo $b->guid."<br/>";
}
?>
效果:
二、如果您有百度小程序的话可以使用这个代码直接生成文章路径,如图
代码:
<?php
include ( "wp-config.php" ) ;
require_once (ABSPATH.'wp-blog-header.php');
global $wpdb;
$qianzui = "/pages/articles/articles?id=";//百度小程序路径地址
$sql="SELECT ID FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY ID DESC ";
$myrows = $wpdb->get_results($sql);
foreach ($myrows as $b) {
echo $qianzui;
echo $b->ID;
echo "<br/>";
}
?>