当前位置:数码通 > 软件

zblogPHP主题调用热门文章、热评文章、最新文章、随机文章方法

来源于 数码通 2023-10-02 04:58

我昨天做的一个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 .= ' //
  • //

    网址。'">'.$文章->标题。'

    // 作者->网址。'">'.$article->作者->StaticName.''.$article->时间('Y-m-d').' //
  • // '; // } // } 返回$str; } //随机文章======================== 因为随机不需要缓存,所以可以将调用写在模板中! //函数 ydblack_randpost() { // 全局 $zbp; // $s = ''; // $array = ydblack_Get_Links( '前一个', '4', '1' ); // foreach ( $array 作为 $article ) { // $s .= '
  • Url . '">' . $article->标题 . '
  • '; // } // 返回 $s; //} //生成最新的文章缓存 函数 ydblack_previouspost() {全局 $zbp; $s = ''; $array = ydblack_Get_Links( '前一个', '4', '1' ); foreach ( $array 作为 $article ) { $s .= '
  • 网址。 '">' . $article->标题 . '
  • '; } //$s .= ''; file_put_contents($zbp->usersdir . 'cache/ydblack_previouspost.txt', $s); 返回 $s; } //获取最新的文章缓存文件 函数 ydblack_previouspost_Cache(){ 全局 $zbp; if (is_file($zbp->usersdir . 'cache/ydblack_previouspost.txt')==true){ $str = file_get_contents($zbp->usersdir . 'cache/ydblack_previouspost.txt'); }别的{ $str = '
  • 请重新提交任何文章,或将其删除,因为此列已被缓存! ! !
  • '; } 返回$str; }

    如何在模板中编写随机部分:

    {$array = ydblack_Get_Links( 'rand', '4', '1' );}
    {foreach $array 作为$相关}
    
  • {$article.Title}

    {$article.Author.StaticName}{$article.Time('Y-m-d')}
  • {/foreach}

    更新最新、热门、消息发布/删除的缓存方法:

    挂:

    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.='网址。 '">' .$article->标题。''; } 返回$str; } // 函数 ydlinux_hotpost() { 全局$zbp; $s = ''; $s.= ydlinux_Get_Links('hot',"9"); 返回 $s; } 函数 ydlinux_commpost() { 全局$zbp; $s = ''; $s.= ydlinux_Get_Links('comm',"9"); 返回 $s; } 函数 ydlinux_randpost() { 全局$zbp; $s = ''; $s.= ydlinux_Get_Links('rand',"9"); 返回 $s; }

     //主函数 函数 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='

  • 任何文章请重新提交或删除! ! !
  • '; } 返回$str; } 函数 tblog5_commentpost_Cache(){ 全局 $zbp; if (is_file($zbp->usersdir . 'cache/tblog5_commentpost.txt')==true){ $str=file_get_contents($zbp->usersdir . 'cache/tblog5_commentpost.txt'); } 别的{ $str=tblog5_commentpost_Cache2(); } 返回$str; } 函数 tblog5_commentpost_Cache2(){ 全局 $zbp; $s = ''; $s.= tblog5_Get_Links('comm',5,$zbp->Config('tblog5')->commcate,$zbp->Config('tblog5')->commdisplay); 返回 $s; }函数 tblog5_hotpost_Cache(){ 全局 $zbp; if (is_file($zbp->usersdir . 'cache/tblog5_hotpost.txt')==true){ $str=file_get_contents($zbp->usersdir . 'cache/tblog5_hotpost.txt'); } 别的{ $str='
  • 请留言
  • ';} 返回$str; }

    调用方式:

    随机发布:{php}echo tblog5_randpost(){/php}

    热门文章:{php}echo tblog5_commentpost_Cache(){/php}

    热门文章:{php}echo tblog5_hotpost_Cache(){/php}

    最新帖子:{php}echo tblog5_previouspost_Cache(){/php}

    登录后参与评论