WordPress获取所有文章链接

时间:2022-05-14
本文章向大家介绍WordPress获取所有文章链接,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

使用方法

  1. 在以下的PHP代码中选择一个复制
  2. 新建GetId.php文件,将代全部码粘贴
  3. 将GetId.php文件上传至网站根目录
  4. 通过浏览器访问该文件即可(例如:www.qcgzxw.cn/GetId.php
  5. 显示内容即为所有已发布的文章链接,复制后保存至本地即可(文件使用完毕后记得删了)

PHP代码

1.获取所有已发布文章(ID)

文章链接:https://www.qcgzxw.cn/2579.html

红色字体即为前缀,绿色即为后缀

<?php   
      include ( "wp-config.php" ) ; 
      require_once (ABSPATH.'wp-blog-header.php'); 
      global $wpdb; 
      $qianzui = "https://www.qcgzxw.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/>";
      }
?>

2.获取所有已发布文章(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/>"; 
      }
?>

3.获取分类下所有文章

<?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 />";
      }
?>

玩法介绍

  1. 批量查询文章是否被收录(筛选出未收录的链接)http://www.link114.cn/baidusl/未被收录的文章链接批量提交百度