一、网站根目录新建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.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/>"; } ?>
三、获取所有已发布文章(guid)
缺点:只能显示原始链接
<?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; $CID = 1;//分类id $sql=“SELECT ID,post_title,post_content FROM wp_posts,wp_term_relationships,wp_term_taxonomy WHERE ID=object_id and wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id and post_type=’post’ and post_status = ‘publish’ and wp_term_relationships.term_taxonomy_id = $CID and taxonomy = ‘category’ order by ID desc”; $myrows = $wpdb->get_results($sql); foreach ($myrows as $b) { echo $b->ID.“<br />”; } ?>