zblog模板和程序默認并不存在讓其中某些分類中的文章不在首頁最新文章列表中顯示的功能,而現在又有不少網站因為某些特定的原因,不想讓一些分類中的文章在首頁最新文章列表中出現(如:文章會重復顯示,或部分分類中的文章并不主要,無需占用首頁那么重要的位置),那么如何解決呢?代碼應該怎樣寫?
其實,想要實現這個目的,是有兩種方法的,這里只給大家說一種,而另一種因為太low了,這里就不寫出來了!
1,我們要先在ZBLOG模板里掛載一個接口:Filter_Plugin_ViewList_Core
Add_Filter_Plugin('Filter_Plugin_ViewList_Core','themeolnews_Index_ViewList');2,完善這個接口中的themeolnews_Index_ViewList函數代碼
function themeolnews_Index_ViewList(&$type,&$page,&$category,&$author,&$datetime,&$tag,&$w,&$pagebar){
global $zbp;
if($type == 'index') {
$indexDelCateListIDStr=$zbp->Config('themeolnews')->indexDelCateListIDStr;//這是后臺主題配置中的分類ID列表,字符串的形式
$indexDelCateListIDArray = strpos($indexDelCateListIDStr,',') !== false ? explode(',',$indexDelCateListIDStr) : array($indexDelCateListIDStr);
foreach($indexDelCateListIDArray as $indexDelCateListID){
$w[]=array('<>','log_CateID',(int)$indexDelCateListID);
}
//其實從此往下的代碼不寫,我們的目的也實現了,但,這并不完美,我們還要重建分頁,因為過濾了分類,文章數量會發生變化
$pagebar = new Pagebar($zbp->option['ZC_INDEX_REGEX']);
$pagebar->PageCount = $zbp->displaycount;
$pagebar->PageNow = $page;
$pagebar->PageBarCount = $zbp->pagebarcount;
}
}到此,我們的zblog模板就可以實現在首頁最新文章列表中排除某(些)指定分類文章的目的了,大家只要熟悉ZBLOGPHP的接口,剩下的處理起來就簡單了!
皖公網安備 34162202000270號