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

首頁 > CMS > Wordpress > 正文

wordpress添加閱讀和評論排行榜功能例子

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

我們在有一些網站可以看到網站文章的瀏覽次數與評論最多的文件排行了,但wordpress中沒有帶這個功能,我們可以進行一些修改達到我們的功能了,下面一起來看看吧.

這里就不介紹頁面的建設方法了,明凱博客里面有介紹,搜索一下就可以了.

一、函數代碼,代碼如下:

  1. <?php 
  2. //文章排行 
  3. function most_viewed($time,$limit) { 
  4. global $wpdb$post
  5. $output = "<ul class=\"hot_views\">"
  6. $most_viewed = $wpdb->get_results("SELECT DISTINCT $wpdb->posts.*, (meta_value+0) AS post_views_count FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON $wpdb->postmeta.post_id = $wpdb->posts.ID WHERE post_date > date_sub( now(), interval $time day ) AND post_type ='post' AND post_status = 'publish' AND meta_key = 'post_views_count' AND post_password = '' ORDER BY post_views_count DESC LIMIT $limit"); 
  7. if($most_viewed) { 
  8. $num=1; 
  9. foreach ($most_viewed as $post) { 
  10. $output .= "\n<li><a href= \"".get_permalink($post->ID)."" rel=\"bookmark\" title=\"".$post->post_title." (".$post->post_views_count."+)\" >$num. "$post->post_title." (".$post->post_views_count."+)</a></li>"
  11. $num++; 
  12. $output .= "<br />"
  13. echo $output
  14. //評論排行 
  15. function most_commmented($time,$limit) { 
  16. global $wpdb$post
  17. $output = "<ul class=\"hot_views\">"
  18. $most_viewed = $wpdb->get_results("SELECT DISTINCT $wpdb->posts.* FROM $wpdb->posts  WHERE post_date > date_sub( now(), interval $time day ) AND post_type ='post' AND post_status = 'publish'  AND post_password = '' ORDER BY comment_count DESC LIMIT $limit"); 
  19. if($most_viewed) { 
  20. $num=1; 
  21. foreach ($most_viewed as $post) { 
  22. $output .= "\n<li><a href= \"".get_permalink($post->ID)."" rel=\"bookmark\" title=\"".$post->post_title." (".$post->comment_count."+)\" >$num. "$post->post_title." (".$post->comment_count."+)</a></li>"//Vevb.com 
  23. $num++; 
  24. $output .= "</ul><br />"
  25. echo $output
  26. ?> 

二、調用方法,代碼如下:

  1. <h2>本月瀏覽量排行</h2> 
  2. <?php most_viewed(30,10); ?> 
  3. <h2>本月評論量排行</h2> 
  4. <?php most_commmented(30,10); ?> 
  5. <h2>年度瀏覽量排行</h2> 
  6. <?php most_viewed(365,10); ?> 
  7. <h2>年度評論量排行</h2> 
  8. <?php most_commmented(365,10); ?> 

三、CSS樣式,代碼如下:

  1. .hot_views li{ 
  2. border-bottom1px dashed #DDD

我這里的樣式非常簡單,因為調用了其他元素的樣式.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 二手房| 项城市| 庆安县| 行唐县| 逊克县| 溆浦县| 宜川县| 苏尼特右旗| 无棣县| 昂仁县| 武城县| 西吉县| 屏南县| 鹿泉市| 宜兰县| 内黄县| 息烽县| 德清县| 武川县| 馆陶县| 洱源县| 靖江市| 革吉县| 汉沽区| 邮箱| 尼玛县| 宁国市| 潼关县| 泌阳县| 昭通市| 古交市| 寻乌县| 兴仁县| 连南| 北票市| 杨浦区| 曲阳县| 盐池县| 泰宁县| 和静县| 成武县|