正文

ZBP調(diào)用文章總數(shù)、置頂數(shù)、tag總數(shù)等相關代碼教程

因為主題模板的差異性,在我們制作或者修改的過程中可能會遇到想要調(diào)用文章總數(shù)、頁面總數(shù)等相關統(tǒng)計信息,ZBP官方wiki是沒有現(xiàn)成的標簽的,別問,問就是佩奇(豬)比較懶。然鵝在zblog后臺首頁“站點信息”也有信息調(diào)用,在百度看了需要教程之后大概統(tǒng)計下有以下幾種方案可行,代碼如下;

方案1

function 主題ID_GetCount($total) {
global $zbp;
//文章數(shù)量{主題ID_GetCount('article')}
if ($total == 'article')
$s = $zbp->db->sql->Count(
$zbp->table['Post'],
array(array('COUNT', 'log_ID', 'num')),
array(array('=', 'log_Type', 0), array('=', 'log_Status', 0))
);
//獲取總共評論的數(shù)量{主題ID_GetCount('comment')}
if ($total == 'comment')
$s = $zbp->db->sql->Count(
$zbp->table['Comment'],
array(array('COUNT', 'comm_ID', 'num')),
array(array('=', 'comm_IsChecking', 0))
);
//獲取標簽數(shù)量{主題ID_GetCount('tag')}
if ($total == 'tag')
$s = $zbp->db->sql->Count(
$zbp->table['Tag'],
array(array('COUNT', 'tag_ID', 'num')),
null
);
//獲取置頂數(shù)量{主題ID_GetCount('istop')}
if ($total == 'istop')
$s = $zbp->db->sql->Count(
$zbp->table['Post'],
array(array('COUNT', 'log_ID', 'num')),
array(array('=', 'log_Type', 0), array('=', 'log_IsTop', 1),array('=', 'log_Status', 0))
);
$s = GetValueInArrayByCurrent($zbp->db->Query($s), 'num');
return $s;
}

除此之外天興大佬也發(fā)布了一些調(diào)用統(tǒng)計數(shù)量的代碼:

方案2

文章總數(shù):{$zbp->cache->all_article_nums}
頁面總數(shù):{$zbp->cache->all_page_nums}
標簽總數(shù):{$zbp->cache->all_tags_nums} <!--無效-->
瀏覽總數(shù):{$zbp->cache->all_views_nums} <!--無效-->
評論總數(shù):{$zbp->cache->all_comments_nums} <!--無效-->

不知道為什么啊,可能是ZBP版本不同所以標簽、瀏覽、評論我用的時候是無效的。不知道什么原因?qū)е隆?

還有一種方案也是我目前在用的,代碼如下:

方案3

//站點信息
function 主題ID_all_views() {
//總訪問量
global $zbp;
$all_views = GetValueInArrayByCurrent($zbp->db->Query('SELECT SUM(log_ViewNums) AS num FROM ' . $GLOBALS['table']['Post']), 'num');
return $all_views;
}
function 主題ID_all_artiles() {
//文章總數(shù)
global $zbp;
$all_artiles = GetValueInArrayByCurrent($zbp->db->Query('SELECT COUNT(*) AS num FROM ' . $GLOBALS['table']['Post'] . ' WHERE log_Type=\'0\''), 'num');
return $all_artiles;
}
function 主題ID_all_comments() {
//評論總數(shù)
global $zbp;
$all_comments = $zbp->cache->all_comment_nums;
return $all_comments;
}

至于選擇使用哪種方案自己決定吧,先收藏再說,免得以后需要時找不著!

Zui后感謝各位大佬的無私奉獻,像你們致敬~~~

聲明:月季網(wǎng)致力月季產(chǎn)業(yè),部分文字和圖片來源網(wǎng)絡,版權歸原作者,如有侵權請聯(lián)系刪除。

月季網(wǎng)

月季網(wǎng)