parent
b480c78344
commit
4c6e080c4d
|
@ -5,7 +5,9 @@ function themeConfig($form) {
|
||||||
$form->addInput($logoUrl);
|
$form->addInput($logoUrl);
|
||||||
$icoUrl = new Typecho_Widget_Helper_Form_Element_Text('icoUrl', NULL, NULL, _t('站点 Favicon 地址'));
|
$icoUrl = new Typecho_Widget_Helper_Form_Element_Text('icoUrl', NULL, NULL, _t('站点 Favicon 地址'));
|
||||||
$form->addInput($icoUrl);
|
$form->addInput($icoUrl);
|
||||||
$jzyear = new Typecho_Widget_Helper_Form_Element_Text('jzyear', NULL, NULL, _t('建站年份'), _t('eg. 2006'));
|
$sticky = new Typecho_Widget_Helper_Form_Element_Text('sticky', NULL, NULL, _t('置顶文章cid'), _t('多篇文章以`|`符号隔开'), _t('会在首页展示置顶文章。'));
|
||||||
|
$form->addInput($sticky);
|
||||||
|
$jzyear = new Typecho_Widget_Helper_Form_Element_Text('jzyear', NULL, NULL, _t('建站年份'), _t('eg. 2006'), _t('会在页脚显示。'));
|
||||||
$form->addInput($jzyear);
|
$form->addInput($jzyear);
|
||||||
$showProfile = new Typecho_Widget_Helper_Form_Element_Radio('showProfile',
|
$showProfile = new Typecho_Widget_Helper_Form_Element_Radio('showProfile',
|
||||||
array('0'=> _t('否'), '1'=> _t('是')),
|
array('0'=> _t('否'), '1'=> _t('是')),
|
||||||
|
|
68
postlist.php
68
postlist.php
|
@ -1,4 +1,70 @@
|
||||||
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
|
<?php
|
||||||
|
//确保退出安全
|
||||||
|
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
|
||||||
|
|
||||||
|
/** 文章置顶 */
|
||||||
|
$sticky = $this->options->sticky ; //置顶的文章id,多个用|隔开
|
||||||
|
|
||||||
|
if ($sticky) {
|
||||||
|
$sticky_cids = array_filter(explode('|', $sticky)); //分割文本并过滤空值
|
||||||
|
$sticky_html = " <span class=sticky--post> 置顶 </span> "; //置顶标题的 html
|
||||||
|
|
||||||
|
$db = Typecho_Db::get();
|
||||||
|
$pageSize = $this->options->pageSize;
|
||||||
|
|
||||||
|
// 构建置顶文章的查询
|
||||||
|
$selectSticky = $this->select()->where('type = ?', 'post');
|
||||||
|
foreach ($sticky_cids as $i => $cid) {
|
||||||
|
if($i == 0)
|
||||||
|
$selectSticky->where('cid = ?', $cid);
|
||||||
|
else
|
||||||
|
$selectSticky->orWhere('cid = ?', $cid);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清空原有文章的列队
|
||||||
|
$this->row = [];
|
||||||
|
$this->stack = [];
|
||||||
|
$this->length = 0;
|
||||||
|
|
||||||
|
// 只在首页第一页展示置顶文章
|
||||||
|
if (($this->_currentPage || $this->currentPage) == 1) {
|
||||||
|
$stickyPosts = $db->fetchAll($selectSticky);
|
||||||
|
foreach ($stickyPosts as $stickyPost) {
|
||||||
|
$stickyPost['title'] = $stickyPost['title'] . $sticky_html;
|
||||||
|
$this->push($stickyPost); //压入列队
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建普通文章的查询,排除置顶文章的 CID
|
||||||
|
$selectNormal = $this->select()
|
||||||
|
->where('type = ?', 'post')
|
||||||
|
->where('status = ?', 'publish')
|
||||||
|
->where('created < ?', time())
|
||||||
|
->order('created', Typecho_Db::SORT_DESC)
|
||||||
|
->page($this->_currentPage, $pageSize);
|
||||||
|
|
||||||
|
foreach ($sticky_cids as $cid) {
|
||||||
|
$selectNormal->where('table.contents.cid != ?', $cid);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 登录用户显示私密文章
|
||||||
|
if ($this->user->hasLogin()) {
|
||||||
|
$uid = $this->user->uid;
|
||||||
|
if ($uid) {
|
||||||
|
$selectNormal->orWhere('authorId = ? AND status = ?', $uid, 'private');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$normalPosts = $db->fetchAll($selectNormal);
|
||||||
|
foreach ($normalPosts as $normalPost) {
|
||||||
|
$this->push($normalPost); //压入列队
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置总数(减去置顶文章数量,以进行正确的分页)
|
||||||
|
$total = $this->getTotal() - count($sticky_cids);
|
||||||
|
$this->setTotal(max($total, 0)); // 确保总数不为负数
|
||||||
|
}
|
||||||
|
?>
|
||||||
<?php while($this->next()): ?>
|
<?php while($this->next()): ?>
|
||||||
<article class="post--item">
|
<article class="post--item">
|
||||||
<div class="content">
|
<div class="content">
|
||||||
|
|
Loading…
Reference in New Issue