导航菜单
登录 注册

之前在调整主题导航菜单的时候想添加所有独立页面,用下面的代码就可以了。

<?php $this->widget('Widget_Contents_Page_List')->to($pages); ?>
<?php if ($pages->have()) : ?>
<ul>
   <?php $pages->parse('<li><a href="{permalink}">{title}</a></li>')
</ul>
<?php endif;?>

但是我不想输出用户中心,所以我就在后台把用户中心页面隐藏了

2020-06-23T09:27:42.png
2020-06-23T09:27:42.png

今天想在右上角用户菜单那添加用户中心链接,但是通过

Widget_Contents_Page_List

无法获取隐藏的页面,不能判断页面是否存在,所以我写了下面的代码用于获取所有前端可访问页面

回复可见
此处内容已隐藏,回复后(需要填写邮箱)可见

这样返回的是

function getAllPages() {
$db = Typecho_Db::get();
if (class_exists('\Typecho\Widget')) {
$widget =  \Widget\Contents\Page\Rows::alloc();
foreach ([
"stack" => [],
"row" => [],
"length" => 0
] as $name => $val) {
try {
$reflect = new ReflectionClass($widget);
$property = $reflect->getProperty($name);
$property->setAccessible(true);
$property->setValue($widget, $val);
} catch (ReflectionException $e) {
}
}
} else {
$widget = new Widget_Contents_Page_List(Typecho_Request::getInstance(), Typecho_Widget_Helper_Empty::getInstance(), null);
}
$db->fetchAll($db->select()
->from('table.contents')
->where('table.contents.type = ?', 'page')
->where('table.contents.status = ? or table.contents.status = ?', 'publish', 'hidden')
->where('table.contents.created < ?', Helper::options()->time), array($widget, 'push'));
return $widget;
}

对象,怎么用不用我多说了吧

服务器安装SG11扩展多版本(宝塔+通用版本)详细教程
上一篇
Accessories Pro 1.1.5 b1 更新说明
下一篇

精选留言

已有 11 条评论

  1. Fay
    江苏省

    这正是我想要的

  2. xxxxx
    湖北省

    测四66668888

  3. anuny
    贵州省

    看看照明实现的

    1. anuny
      贵州省

      最简单的实现

      use Typecho\Db;
      use Widget\Base\Contents;

      function getpages(){

      $db = Db::get();
      $row = $db->fetchRow($db->select()->from('table.contents')->where('type=page'));
      Contents::alloc()->to($pages);
      return $pages->push($row);

      }