4

利用代码获取WordPress网站内所有的文章链接

 2 years ago
source link: https://www.huhexian.com/18488.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

利用代码获取WordPress网站内所有的文章链接

2021-12-2114:54:29评论843字

我们使用wordpress建立好网站之后,我们可以在后台通过插件等形式实现sitemap,但是随着文章的增多,查找网站文章链接的方法越来越难,这时候我们如何通过其他方式获取WordPress网站内所有的文章链接呢?下面就来教大家利用代码获取WordPress网站内所有的文章链接。

利用代码获取WordPress网站内所有的文章链接

网站根目录新建allurl.php文件,将代全部码粘贴通过浏览器访问该文件即可(例如:域名/allurl.php)

  1. <?php
  2. include ( "wp-config.php" ) ;
  3. require_once (ABSPATH.'wp-blog-header.php');
  4. global $wpdb;
  5. $qianzhui = "http://huhexian.com/";//网站域名
  6. $houzhui = ".html";//文章后缀
  7. $sql="SELECT ID FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY ID DESC ";
  8. $myrows = $wpdb->get_results($sql);
  9. foreach ($myrows as $b) {
  10. echo $qianzhui;
  11. echo $b->ID;
  12. echo $houzhui."<br/>";
  13. ?>

如果你的是ID的话(就是你的文章链接是这样的 https://www.ly522.com/?p=520)就使用这个代码

  1. <?php
  2. include ( "wp-config.php" ) ;
  3. require_once (ABSPATH.'wp-blog-header.php');
  4. global $wpdb;
  5. $sql="SELECT guid FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY ID DESC ";
  6. $myrows = $wpdb->get_results($sql);
  7. foreach ($myrows as $b) {
  8. echo $b->guid."<br/>";
  9. ?>

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK