国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > CMS > Wordpress > 正文

wordpress顯示隨機文章實現方法

2024-09-07 00:50:19
字體:
來源:轉載
供稿:網友

首頁隨機顯示文章 在wordpress里面并不難,也不需要安裝復雜的插件,只需要在合適的php文件里面添加如下代碼,這個完全歸功于wordpress的模塊化結構.

1.使用get_posts生成隨機文章,代碼如下:

  1. <?php 
  2. $rand_posts = get_posts('numberposts=10&orderby=rand'); 
  3. foreach$rand_posts as $post ) : 
  4. ?> 
  5. <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> 
  6. <?php endforeach; ?> 

2.使用隨處可見的query_psots,代碼如下:

  1. <?php 
  2. query_posts('showposts=10&orderby=rand'); 
  3. if ( have_posts() ) : while ( have_posts() ) : the_post(); 
  4. ?> 
  5. <li><em><?php echo $j++;?></em><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> 
  6. <?php 
  7. endwhileelse
  8. ?> 

沒有可顯示的文章

  1. <?php 
  2. endif
  3. wp_reset_query(); 
  4. ?> 

3.自定隨機文章顯示,代碼如下:

  1. <ul> 
  2.     <?php 
  3.     $args = array'numberposts' => 5, 'orderby' => 'rand' ); 
  4.     $rand_posts = get_posts( $args ); 
  5.     foreach$rand_posts as $post ) : ?> 
  6.         <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> 
  7.     <?php endforeach; ?> 
  8.     </ul> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 中山市| 河源市| 津市市| 东阿县| 赫章县| 阳朔县| 汶上县| 怀来县| 库尔勒市| 长岛县| 黄龙县| 克拉玛依市| 永安市| 蒙城县| 广水市| 普格县| 永定县| 郸城县| 从化市| 新密市| 延边| 南澳县| 理塘县| 渝中区| 蒲江县| 昌图县| 芮城县| 肇庆市| 甘谷县| 鲁山县| 芜湖县| 武川县| 句容市| 云霄县| 饶平县| 兴城市| 拜城县| 获嘉县| 德庆县| 德庆县| 林周县|