我昨天做的一个zblogPHP主题也同时使用了热门文章、热评文章、随机文章的功能。
1 {IMG_1: Ahr0CHM6LY93D3Cuexprdhcuy29tlmnul3pix3vzzxjzl3VWBG9Hzymde3lzaylziWMJI0MTQ4NZKZOTA5NS5WBMC =/} // 排名随机最新热门消息 函数 ydblack_Get_Links( $type, $num, $tblogcate ) { 全局 $zbp、$arrays、$order; //$str = ''; $str = ''; if ( $type == '前一个' ) { $order = array( 'log_PostTime' => 'DESC' ); } if ( $type == '热' ) { $order = array( 'log_ViewNums' => 'DESC' ); } if ( $type == 'comm' ) { $order = array( 'log_CommNums' => 'DESC' ); } if ( $zbp->db->type == "sqlite" ) { if ( $type == 'rand' ) { $order = array( 'random()' => '' ); } } 别的 { if ( $type == 'rand' ) { $order = array( 'rand()' => '' ); } } $stime = 时间(); $y时间 = (24) * 30 * 24 * 60 * 60; //时间可以控制 $ztime = $stime - $ytime; 如果(空($tblogcate)){$where = array( array( '=', 'log_Status', '0' ), array( '>', 'log_PostTime', $ztime ) ); } 别的 { $where = array( array( '=', 'log_Status', '0' ), array( '>', 'log_PostTime', $ztime ), array( '=', 'log_CateID', $tblogcate ) ); } $str = $zbp->GetArticleList( array( '*' ), $where, $order, array( $num ), '' ); //注意$str // if ( $type == 'rand' ) { //随机 // foreach ( $array 作为 $article ) { // $str .= ' //如何在模板中编写随机部分:
{$array = ydblack_Get_Links( 'rand', '4', '1' );} {foreach $array 作为$相关}
更新最新、热门、消息发布/删除的缓存方法:
挂:
Add_Filter_Plugin('Filter_Plugin_PostArticle_Succeed','ydblack_previouspost');//提交更新Add_Filter_Plugin('Filter_Plugin_DelArticle_Succeed','ydblack_previouspost');//删除更新
最新、热门、留言调用代码:
ydblack_previouspost_Cache()
//热门命令
函数 ydlinux_Get_Links($type,$num){
全局 $zbp,$str,$order;
$str='';
if($type=='前一个'){
$order = array('log_PostTime'=>'DESC');
}
if($type=='热门'){
$order = array('log_ViewNums'=>'DESC');
}
if($type=='comm'){
$order = array('log_CommNums'=>'DESC');
}
if ($zbp->db->type=="sqlite"){
if($type=='rand'){
$order = array('random()'=>'');
}
}
别的
{
if($type=='rand'){
$order = array('rand()'=>'');
}
}
$where = array(array('=','log_Status','0'));
$array = $zbp->GetArticleList(array('*'),$where,$order,array($num),'');foreach($array as $key=>$article){
$i = $key+1;
$str.='
//主函数
函数 tblog5_Get_Links($type,$num,$tblogcate,$tblogThumb){
全局 $zbp,$str,$order;
$str='';
if($type=='前一个'){
$order = array('log_PostTime'=>'DESC');
}
if($type=='热门'){
$order = array('log_ViewNums'=>'DESC');
}
if($type=='comm'){
$order = array('log_CommNums'=>'DESC');
}if ($zbp->db->type=="sqlite"){
if($type=='rand'){
$order = array('random()'=>'');
}
}
别的
{
if($type=='rand'){
$order = array('rand()'=>'');
}
}
$stime = time();
$ytime = ($zbp->Config('tblog5')->月)*30*24*60*60;
$ztime = $stime-$ytime;
如果(空($tblogcate)){
$where = array(array('=','log_Status','0'),array('>','log_PostTime',$ztime));
}
别的 {
$where = array(array('=','log_Status','0'),array('>','log_PostTime',$ztime),array('=','log_CateID',$tblogcate));
}
$array = $zbp->GetArticleList(array('*'),$where,$order,array($num),'');
foreach($array 作为$article){
如果($tblogThumb==“1”){
$clsjtp=tblog5_firstimg($article);
$str .='Url。'" class="_ajx ease sb-border">标题。'">'。$article->时间('Y-m-d')。''.$文章->标题.'';
}
别的{$str .='Url。'" class="_ajx ease sb-border sb_wt">'.$article->时间('Y-m-d').''.$article- >标题.'';
}
}
返回$str;
}
// 存储路径
函数 tblog5_previouspost() {
全局$zbp;
$s = '';
$s.= tblog5_Get_Links('previous',"5",$zbp->Config('tblog5')->previouscate,$zbp->Config('tblog5')->previousdisplay);
$s.='';
file_put_contents($zbp->usersdir . 'cache/tblog5_previouspost.txt', $s);
}
函数 tblog5_randpost() {
全局$zbp;
$s = '';
$s.= tblog5_Get_Links('rand',"5",$zbp->Config('tblog5')->randcate,$zbp->Config('tblog5')->randdisplay);
返回 $s;
}
函数 tblog5_hotpost() {
全局$zbp;
$s = '';
$s.= tblog5_Get_Links('hot',"5",$zbp->Config('tblog5')->hotcate,$zbp->Config('tblog5')->hotdisplay);
$s.='';
file_put_contents($zbp->usersdir . 'cache/tblog5_hotpost.txt', $s);
}
函数 tblog5_commentpost() {
全局$zbp;
$s = '';$s.= tblog5_Get_Links('comm',"5",$zbp->Config('tblog5')->commcate,$zbp->Config('tblog5')->commdisplay);
$s .= '';
File_put_contents($zbp->usersdir . 'cache/tblog5_commentpost.txt', $s);
}
//获取路径
函数 tblog5_previouspost_Cache(){
全局 $zbp;
if (is_file($zbp->usersdir . 'cache/tblog5_previouspost.txt')==true){
$str=file_get_contents($zbp->usersdir . 'cache/tblog5_previouspost.txt');
}别的{
$str='
调用方式:
随机发布:{php}echo tblog5_randpost(){/php}
热门文章:{php}echo tblog5_commentpost_Cache(){/php}
热门文章:{php}echo tblog5_hotpost_Cache(){/php}
最新帖子:{php}echo tblog5_previouspost_Cache(){/php}