typecho 使用Helper::widgetById()会报错

新手上路,请多包涵

Helper::widgetById()该如何用?

我在主题中archive.php使用
<?php print_r(Helper::widgetById('contents', $this->cid)->category); ?>
就会报错:

Warning: Missing argument 1 for Widget_Abstract::__construct(), called in /www/wwwroot/blog1.1/var/Helper.php on line 57 and defined in /www/wwwroot/blog1.1/var/Widget/Abstract.php on line 62

虽然执行结果出来了,但上面的错误如何解决?

使用的是版本typecho 1.1 (17.10.30),但经测试在1.2 (18.1.29)中却没有报错。

起因是

我在给置顶插件
Typecho_Plugin::factory('Widget_Archive')->categoryHandle = array('Sticky_Plugin', 'stickyC');
添加个分类判断

    public static function stickyC($archive, $select)
    {
        $config  = Typecho_Widget::widget('Widget_Options')->plugin('Sticky');
        $sticky_cid = $config->sticky_cid ? explode(',', strtr($config->sticky_cid, ' ', ',')) : '';
        if (!$sticky_cid) return;

        $db = Typecho_Db::get();
        $paded = $archive->request->get('page', 1);
        
        foreach($sticky_cid as $cid) {
          $sticky_post = $db->fetchRow($archive->select()->where('cid = ?', $cid));
            if ($cid && $sticky_post) {
               if ($paded == 1) {
                $sticky_post['title'] = $sticky_post['title'] . $config->sticky_html.$archive->category;
                $archive->push($sticky_post);
              }
              $select->where('table.contents.cid != ?', $cid);

            }
     }

这里的stickyC($archive, $select)两个参数不是很明白它的意思,用$archive->category得到的分类名是错的,求教得到该cid的分类的正确方法。

阅读 1.4k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进