导航菜单

下午修改Typecho主题想把首页文章过滤的功能集成到主题,高级查询其实很简单直接继承Widget_Abstract_Contents以及其子类都可以,重写一下select()方法就可以了。传过来的参数使用逗号隔开,explode函数分割就行。

class XMP_Post_Query extends Widget_Abstract_Contents {
    public function execute() {
        ...(省略部分代码)
        if (isset($this->parameter->excludeTemplate) && $this->parameter->excludeTemplate !== "") {
            $ext_arr = array_unique(explode(",", $this->parameter->excludeTemplate));
            foreach ($ext_arr as $ext) {
                $select = $select->where('table.contents.template <> ?', $ext);
            }
        }
    }
}

其中的关键语句$select = $select->where('table.contents.template <> ?', $ext);是我想当然写的,尝试了1个多小时,改来改去,我怀疑各种转义拼接导致问题,结果都不是。
没办法了,下载SQL Expert在数据库里操作把。

select title,type,template from typecho_contents where(type = 'post') and (template != 'post-note.php')
(结果是空的???)

那我再尝试一下template = null,还是空的。。。
isnotnull.png
没办法,翻了一下数据库的书,原来要用is (not) null
is_not_null查询结果.png