当前位置:首页 > CMS教程 > 其它CMS > 列表

ZBLOG调用随机文章、热门文章、热评文章的php代码

发布:smiling 来源: PHP粉丝网  添加日期:2015-04-04 11:13:18 浏览: 评论:0 

Z-Blog是由RainbowSoft Studio开发的一款小巧而强大的基于Asp/php平台的Blog程序了,下文介绍的是php版本的ZBLOG调用随机文章、热门文章、热评文章代码.

使用方法:

第一、在我们的主题目录中需要创建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. if (!is_array($option)) { 
  16. $option = array(); 
  17. } 
  18. if (!isset($option['only_ontop'])) 
  19. $option['only_ontop'] = false; 
  20. if (!isset($option['only_not_ontop'])) 
  21. $option['only_not_ontop'] = false; 
  22. if (!isset($option['has_subcate'])) 
  23. $option['has_subcate'] = false; 
  24. if (!isset($option['is_related'])) 
  25. $option['is_related'] = false; 
  26. if ($option['is_related']) { 
  27. $at = $zbp->GetPostByID($option['is_related']); 
  28. $tags = $at->Tags; 
  29. if (!$tags) 
  30. return array(); 
  31. $count = $count + 1; 
  32. } 
  33. if ($option['only_ontop'] == true) { 
  34. $w[] = array('=', 'log_IsTop', 0); 
  35. } elseif ($option['only_not_ontop'] == true) { 
  36. $w[] = array('=', 'log_IsTop', 1); 
  37. } 
  38. $w = array(); 
  39. $w[] = array('=', 'log_Status', 0); 
  40. $articles = array(); 
  41. if (!is_null($cate)) { 
  42. $category = new Category; 
  43. $category = $zbp->GetCategoryByID($cate); 
  44. if ($category->ID > 0) { 
  45. if (!$option['has_subcate']) { 
  46. $w[] = array('=', 'log_CateID', $category->ID); 
  47. } else { 
  48. $arysubcate = array(); 
  49. $arysubcate[] = array('log_CateID', $category->ID); 
  50. foreach ($zbp->categorys[$category->ID]->SubCategorys as $subcate) { 
  51. $arysubcate[] = array('log_CateID', $subcate->ID); 
  52. } 
  53. $w[] = array('array', $arysubcate); 
  54. } 
  55. } 
  56. } 
  57. if (!is_null($auth)) { 
  58. $author = new Member; 
  59. $author = $zbp->GetMemberByID($auth); 
  60. if ($author->ID > 0) { 
  61. $w[] = array('=', 'log_AuthorID', $author->ID); 
  62. } 
  63. } 
  64. if (!is_null($date)) { 
  65. $datetime = strtotime($date); 
  66. if ($datetime) { 
  67. $datetitle = str_replace(array('%y%', '%m%'), array(date('Y', $datetime), date('n', $datetime)), $zbp->lang['msg']['year_month']); 
  68. $w[] = array('BETWEEN', 'log_PostTime', $datetime, strtotime('+1 month', $datetime)); 
  69. } 
  70. } 
  71. if (!is_null($tags)) { 
  72. $tag = new Tag; 
  73. if (is_array($tags)) { 
  74. $ta = array(); 
  75. foreach ($tags as $t) { 
  76. $ta[] = array('log_Tag', '%{' . $t->ID . '}%'); 
  77. } 
  78. $w[] = array('array_like', $ta); 
  79. unset($ta); 
  80. } else { 
  81. if (is_int($tags)) { 
  82. $tag = $zbp->GetTagByID($tags); 
  83. } else { 
  84. $tag = $zbp->GetTagByAliasOrName($tags); 
  85. } 
  86. if ($tag->ID > 0) { 
  87. $w[] = array('LIKE', 'log_Tag', '%{' . $tag->ID . '}%'); 
  88. } 
  89. } 
  90. } 
  91. if (is_string($search)) { 
  92. $search=trim($search); 
  93. if ($search!=='') { 
  94. $w[] = array('search', 'log_Content', 'log_Intro', 'log_Title', $search); 
  95. } 
  96. } 
  97. if(!emptyempty($order)){ 
  98. if($order=='new'){ 
  99. $order = array('log_PostTime'=>'DESC'); 
  100. } 
  101. if($order=='hot'){ 
  102. $order = array('log_ViewNums'=>'DESC'); 
  103. } 
  104. if($order=='comm'){ 
  105. $order = array('log_CommNums'=>'DESC'); 
  106. } 
  107. if($order=='rand'){ 
  108. $order = array('rand()'=>' '); 
  109. } //开源软件:phpfensi.com 
  110. } 
  111. $articles = $zbp->GetArticleList('*', $w, $order, $count, null, false); 
  112. if ($option['is_related']) { 
  113. foreach ($articles as $k => $a) { 
  114. if ($a->ID == $option['is_related']) 
  115. unset($articles[$k]); 
  116. } 
  117. if (count($articles) == $count){ 
  118. array_pop($articles); 
  119. } 
  120. } 
  121. return $articles; 
  122. } 

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

热门文章,代码如下:

  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篇热门文章,热评文章,代码如下:

  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> 

直接用zblogphp的原生代码,代码如下:

  1. <img src="{php}$pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg|\.png]))[\'|\"].*?[\/]?>/"; 
  2. $content = $article->Content; 
  3. preg_match_all($pattern,$content,$matchContent); 
  4. echo $matchContent[1][0]; 
  5. {/php}" /> 

这些代码前台编译出来的html代码就是:<img src="图片地址">,可以加在任意想调用的地方.

PHP版随机文章的调用方法:

不会写插件,直接爆方法.

1、打开zb_system\function\c_system_event.php

在743行,$zbp->AddBuildModule('previous');后面添加$zbp->AddBuildModule('sjarticles');

在781行,$zbp->AddBuildModule('previous');后面添加$zbp->AddBuildModule('sjarticles');

在最后后面添加如下代码:

  1. function BuildModule_sjarticles(){ 
  2.         global $zbp; 
  3.  
  4.         $articles=$zbp->GetArticleList( 
  5.                 array('*'), 
  6.                 array(array('=','log_Type',0),array('=','log_Status',0)), 
  7.                 array('rand()'=>' '), 
  8.                 array(10), 
  9.                 null 
  10.         ); 
  11.         $s=''; 
  12.         foreach ($articles as $article) { 
  13.                 $s .='' . $article->Title . ''; 
  14.         } 
  15.         return $s; 
  16. } 

2、打开zb_system\function\lib\zblogphp.php

在218行,$this->RegBuildModule('previous','BuildModule_previous');后面添加$this->RegBuildModule('hotarticles','BuildModule_sjarticles');

3、打开数据库,在zbp_module表,添加新数据,15,热门文章,sjarticles,,0,divsjarticles,ul,0,system,0

调用方法:在相应地方调用{$modules['sjarticles'].Content}

Tags: ZBLOG随机文章 ZBLOG热门文章

分享到: