怎样用sql语句调用wordpress某分类下的所有信息

  1. <div class=“mb-a left dInline mb-dl”>  
  2.           
  3.         <?php    
  4.         //用sql语句调用某分类下的所有信息,$CID为分类id  
  5.         $CID=1;  
  6. global $wpdb;    
  7. $rs = $wpdb->get_results(“select * 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 asc limit 0,3” );    
  8. //p($rs);  
  9. foreach($rs as $cat)    
  10. {?>    
  11.             <div class=“mbDiv”>  
  12.   
  13.                     <img src=“<?php  
  14.                     //正则匹配内容中的图片 
  15.                     $post_thumbnail_src = ”; 
  16.         ob_start(); 
  17.         ob_end_clean(); 
  18.         $output = preg_match_all(‘/<img.+src=[\'”]([^\’“]+)[\'”].*>/i’, $cat->post_content, $matches);  
  19.         $post_thumbnail_src = $matches [1] [0];     
  20.           
  21.                     echo $post_thumbnail_src; ?>” width=”186” height=”132” />  
  22.                     <p>  
  23.                         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span><?php echo $cat->post_title;?></span>  
  24.                         &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span> <?php echo $cat->post_excerpt;?> </span>  
  25.                     </p>  
  26.                   
  27.             </div>  
  28.               
  29.             <?php }?>  
  30.              
  31.         </div>  

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

www.admin122.com 关注微信
24小时客服在线