zoukankan      html  css  js  c++  java
  • wordpress通过$wpdb获取一个分类下所有的文章

    在wordpress程序根目录下新建一个php文件,粘贴下面的代码

    如下面的代码注释,修改$CID这个分类id,就可以获取这个分类下的文章了。这个查询需要联合三个表wp_posts、wp_term_relationships、wp_term_taxonomy,

    根据term_taxonomy_id获取文章标号,post_status = ‘publish’ 是指文章已经发布,post_type=’post’ 是指记录类型是文章,taxonomy = ‘category’ 是指类型是目录。

    然后运行这个文件,就可以读取这个分类下的所有的文章了。

    <?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 />";//这是文章ID
          echo $b->post_title."<br />";//这是文章标题
          echo $b->post_content."<br />";//这是文章内容
          }
    
    ?> 
  • 相关阅读:
    享元模式(Flyweight)
    策略模式(strategy)
    访问者模式(Visitor)
    适配器模式(Adapter)
    外观模式(Facade)
    代理模式(Proxy)
    ORACLE 表空间扩展方法
    Oracle XML Publisher
    DB.Package procedure Report
    case ... end 语句
  • 原文地址:https://www.cnblogs.com/hxqseo/p/5553669.html
Copyright © 2011-2022 走看看