正文:
1.在网站的根目录下新建一个 geturl.php 文件,粘贴所有通过浏览器访问该文件的代码(例如,域名/jujyg.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.xxx.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/>";
}
?>
转载请注明:汇站网 » (代码教程)Php 代码获得 WordPress 网站上所有文章的链接