6

ZBlog自定义列表文章数和分页按钮数

 3 years ago
source link: https://www.feidaoboke.com/post/zblog-change-list-article-count.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

ZBlog自定义列表文章数和分页按钮数

类别:编程 日期:2021-05-21 评论:1

ZBlog的后台页面设置中有个列表页显示文章的数量的设置项,用来控制文章列表页面每页显示的文章数目。这个数字默认是覆盖全局所有文章列表页面的,全局所有默认列表页都会显示这个数目的文章。

有时候我们需要在特定的地方显示自定义的数目,可以通过拦截接口的方法实现。

ZBlog中有这样子一个过滤器接口: Filter_Plugin_ViewList_Core ,通过它就可以自定义文章列表数目。

/*
'**************************************************<
'类型:Filter
'名称:Filter_Plugin_ViewList_Core
'参数:&$type,&$page,&$category,&$author,&$datetime,&$tag,&$w,&$pagebar
'说明:定义列表核心接口
'调用:
'**************************************************>
 */
DefinePluginFilter('Filter_Plugin_ViewList_Core');

在ZBlog的源代码可以看到这个过滤器的最后一个参数是$pagebar,在主题(插件)中对它$pagebar→PageCount进行修改就可以实现列表数目的修改。

如果要修改每个列表页下方的分页f翻页按钮数,则修改$pagebar→PageBarCount即可。

比如,我在主题中要实现在手机上显示文章数比在电脑上少1篇,在手机上的分页按钮只显示4个,代码入下:

//在激活主题(插件)的时候挂接 XXX_ChangePageListCount 方法。
Add_Filter_Plugin('Filter_Plugin_ViewList_Core', 'XXX_ChangePageListCount');
// 在 XXX_ChangePageListCount 方法中具体修改定义数目的逻辑。
function XXX_ChangePageListCount(&$type, &$page, &$category, &$author, &$datetime, &$tag, &$w, &$pagebar){
    if(is_mobile()){
        global $zbp;
        //每页文章数
        $pagebar->PageCount = $zbp->displaycount - 1;
        // 分页按键数
        $pagebar->PageBarCount = 4; 
    }
}

这其中有个is_mobile()的方法,用于判断是手机在浏览还是电脑在浏览网站,通过浏览器的 USER_AGENT 判断,不在本文讨论范围内。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK