之前在调整主题导航菜单的时候想添加所有独立页面,用下面的代码就可以了。
<?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;?>
但是我不想输出用户中心,所以我就在后台把用户中心页面隐藏了
今天想在右上角用户菜单那添加用户中心链接,但是通过
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;
}
对象,怎么用不用我多说了吧
终于给我取消收钱了,流泪
为了看隐藏
终于给我取消收钱了,流泪
看看
试试
这正是我想要的
测四66668888
看看照明实现的
最简单的实现
use Typecho\Db;
use Widget\Base\Contents;
function getpages(){
}
尝试一下