首页 > 网站 > 建站经验 > 正文

ZBLOG PHP调用随机文章、热门文章、热评文章程序

2024-08-30 19:06:47
字体:大 中 小
来源:转载
供稿:网友

本文章来为各位介绍一篇关于ZBLOG PHP调用随机文章、热门文章、热评文章的例子,希望这篇教程能够为各位同学带来帮助的哦.

使用方法:

第一、在我们的主题目录中需要创建include.php文件,如果有就直接添加脚本,代码如下:

  1. /** 
  2. * 获取文章列表 
  3. * @param int $count 数量 
  4. * @param null $cate 分类ID 
  5. * @param null $auth 用户ID 
  6. * @param null $date 日期 
  7. * @param null $tags 标签 
  8. * @param null $search 搜索关键词 
  9. * @param null $order 排序 
  10. * @param null $option 
  11. * @return array|mixed 
  12. */ 
  13. function TcgetList($count = 10, $cate = null, $auth = null, $date = null, $tags = null, $search = null, $option = null,$order=null) { 
  14. global $zbp; 
  15.  
  16. if (!is_array($option)) { 
  17. $option = array(); 
  18. } 
  19.  
  20. if (!isset($option['only_ontop'])) 
  21. $option['only_ontop'] = false; 
  22. if (!isset($option['only_not_ontop'])) 
  23. $option['only_not_ontop'] = false; 
  24. if (!isset($option['has_subcate'])) 
  25. $option['has_subcate'] = false; 
  26. if (!isset($option['is_related'])) 
  27. $option['is_related'] = false; 
  28.  
  29. if ($option['is_related']) { 
  30. $at = $zbp->GetPostByID($option['is_related']); 
  31. $tags = $at->Tags; 
  32. if (!$tags) 
  33. return array(); 
  34. $count = $count + 1; 
  35. } 
  36.  
  37. if ($option['only_ontop'] == true) { 
  38. $w[] = array('=', 'log_IsTop', 0); 
  39. } elseif ($option['only_not_ontop'] == true) { 
  40. $w[] = array('=', 'log_IsTop', 1); 
  41. } 
  42.  
  43. $w = array(); 
  44. $w[] = array('=', 'log_Status', 0); 
  45.  
  46. $articles = array(); 
  47.  
  48. if (!is_null($cate)) { 
  49. $category = new Category; 
  50. $category = $zbp->GetCategoryByID($cate); 
  51.  
  52. if ($category->ID > 0) { 
  53.  
  54. if (!$option['has_subcate']) { 
  55. $w[] = array('=', 'log_CateID', $category->ID); 
  56. } else { 
  57. $arysubcate = array(); 
  58. $arysubcate[] = array('log_CateID', $category->ID); 
  59. foreach ($zbp->categorys[$category->ID]->SubCategorys as $subcate) { 
  60. $arysubcate[] = array('log_CateID', $subcate->ID); 
  61. } 
  62. $w[] = array('array', $arysubcate); 
  63.  
  64. } 
  65.  
  66. } 
  67. } 
  68.  
  69. if (!is_null($auth)) { 
  70. $author = new Member; 
  71. $author = $zbp->GetMemberByID($auth); 
  72.  
  73. if ($author->ID > 0) { 
  74. $w[] = array('=', 'log_AuthorID', $author->ID); 
  75. } 
  76. } 
  77.  
  78. if (!is_null($date)) { 
  79. $datetime = strtotime($date); 
  80. if ($datetime) { 
  81. $datetitle = str_replace(array('%y%', '%m%'), array(date('Y', $datetime), date('n', $datetime)), $zbp->lang['msg']['year_month']); 
  82. $w[] = array('BETWEEN', 'log_PostTime', $datetime, strtotime('+1 month', $datetime)); 
  83. } 
  84. } 
  85.  
  86. if (!is_null($tags)) { 
  87. $tag = new Tag; 
  88. if (is_array($tags)) { 
  89. $ta = array(); 
  90. foreach ($tags as $t) { 
  91. $ta[] = array('log_Tag', '%{' . $t->ID . '}%'); 
  92. } 
  93. $w[] = array('array_like', $ta); 
  94. unset($ta); 
  95. } else { 
  96. if (is_int($tags)) { 
  97. $tag = $zbp->GetTagByID($tags); 
  98. } else { 
  99. $tag = $zbp->GetTagByAliasOrName($tags); 
  100. } 
  101. if ($tag->ID > 0) { 
  102. $w[] = array('LIKE', 'log_Tag', '%{' . $tag->ID . '}%'); 
  103. } 
  104. } 
  105. } 
  106.  
  107. if (is_string($search)) { 
  108. $search=trim($search); 
  109. if ($search!=='') { 
  110. $w[] = array('search', 'log_Content', 'log_Intro', 'log_Title', $search); 
  111. } 
  112. } 
  113.  
  114. if(!emptyempty($order)){ 
  115. if($order=='new'){ 
  116. $order = array('log_PostTime'=>'DESC'); 
  117. } 
  118. if($order=='hot'){ 
  119. $order = array('log_ViewNums'=>'DESC'); 
  120. } 
  121. if($order=='comm'){ 
  122. $order = array('log_CommNums'=>'DESC'); 
  123. } 
  124. if($order=='rand'){ 
  125. $order = array('rand()'=>' '); 
  126. } 
  127. } 
  128.  
  129. $articles = $zbp->GetArticleList('*', $w, $order, $count, null, false); 
  130. //Vevb.com 
  131. if ($option['is_related']) { 
  132. foreach ($articles as $k => $a) { 
  133. if ($a->ID == $option['is_related']) 
  134. unset($articles[$k]); 
  135. } 
  136. if (count($articles) == $count){ 
  137. array_pop($articles); 
  138. } 
  139. } 
  140.  
  141. return $articles; 
  142.  
  143. } 

然后就是在我们需要的界面模板中调用。

A - 随机文章,代码如下:

  1. {$array=TcgetList(10,null,null,null,null,null,null,'rand');} 
  2. <ul id="related"> 
  3. {foreach $array as $related} 
  4. <li><span class="time">{$related.Time('m-d')}</span><span class="title"><a href="{$related.Url}" title="{$related.Title}">{$related.Title}</a></span></li> 
  5. {/foreach} 
  6. </ul> 

随机10篇文章

B - 热门文章,代码如下:

  1. {$array=TcgetList(10,null,null,null,null,null,null,'hot');} 
  2. <ul id="related"> 
  3. {foreach $array as $related} 
  4. <li><span class="time">{$related.Time('m-d')}</span><span class="title"><a href="{$related.Url}" title="{$related.Title}">{$related.Title}</a></span></li> 
  5. {/foreach} 
  6. </ul> 

调用10篇热门文章

C - 热评文章,代码如下:

  1. {$array=TcgetList(10,null,null,null,null,null,null,'comm';} 
  2. <ul id="related"> 
  3. {foreach $array as $related} 
  4. <li><span class="time">{$related.Time('m-d')}</span><span class="title"><a href="{$related.Url}" title="{$related.Title}">{$related.Title}</a></span></li> 
  5. {/foreach} 
  6. </ul> 

调用10篇热评文章,具体的根据我们实际使用调用就可以.

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表