This commit is contained in:
浪子 2024-08-31 10:57:54 +08:00
parent 74b7bcecff
commit 8c9dd30c52
2 changed files with 70 additions and 73 deletions

View File

@ -5,7 +5,7 @@ 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);
$sticky = new Typecho_Widget_Helper_Form_Element_Text('sticky', NULL, '0', _t('置顶文章cid'), _t('多篇文章以`|`符号隔开'), _t('会在首页展示置顶文章。')); $sticky = new Typecho_Widget_Helper_Form_Element_Text('sticky', NULL, NULL, _t('置顶文章cid'), _t('多篇文章以`|`符号隔开'), _t('会在首页展示置顶文章。'));
$form->addInput($sticky); $form->addInput($sticky);
$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('是')),

View File

@ -4,13 +4,14 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit;
/** 文章置顶 */ /** 文章置顶 */
$sticky = $this->options->sticky; // 置顶的文章id多个用|隔开 $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(); $db = Typecho_Db::get();
$pageSize = $this->options->pageSize; $pageSize = $this->options->pageSize;
if ($sticky && !empty(trim($sticky))) {
$sticky_cids = array_filter(explode('|', $sticky)); // 分割文本并过滤空值
if (!empty($sticky_cids)) {
$sticky_html = " <span class='sticky--post'> 置顶 </span> "; // 置顶标题的 html
// 清空原有文章的队列 // 清空原有文章的队列
$this->row = []; $this->row = [];
$this->stack = []; $this->stack = [];
@ -56,29 +57,24 @@ if ($sticky) {
foreach ($sticky_cids as $cid) { foreach ($sticky_cids as $cid) {
$selectNormal->where('table.contents.cid != ?', $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);
}
} else { } else {
// 如果没有置顶文章,正常分页 // 如果sticky_cids为空使用默认查询
$selectNormal = $this->select() $selectNormal = $this->select()
->where('type = ?', 'post') ->where('type = ?', 'post')
->where('status = ?', 'publish') ->where('status = ?', 'publish')
->where('created < ?', time()) ->where('created < ?', time())
->order('created', Typecho_Db::SORT_DESC) ->order('created', Typecho_Db::SORT_DESC)
->page(isset($this->currentPage) ? $this->currentPage : 1, $this->options->pageSize); ->page(isset($this->currentPage) ? $this->currentPage : 1, $pageSize);
}
} else {
// 如果没有置顶文章,使用默认查询
$selectNormal = $this->select()
->where('type = ?', 'post')
->where('status = ?', 'publish')
->where('created < ?', time())
->order('created', Typecho_Db::SORT_DESC)
->page(isset($this->currentPage) ? $this->currentPage : 1, $pageSize);
}
// 登录用户显示私密文章 // 登录用户显示私密文章
if ($this->user->hasLogin()) { if ($this->user->hasLogin()) {
@ -90,16 +86,17 @@ if ($sticky) {
$normalPosts = $db->fetchAll($selectNormal); $normalPosts = $db->fetchAll($selectNormal);
// 清空原有文章的队列 // 如果之前没有清空队列(没有置顶文章的情况),现在清空
if (empty($sticky) || empty(trim($sticky)) || empty($sticky_cids)) {
$this->row = []; $this->row = [];
$this->stack = []; $this->stack = [];
$this->length = 0; $this->length = 0;
}
// 压入正常文章到文章队列 // 压入正常文章到文章队列
foreach ($normalPosts as $normalPost) { foreach ($normalPosts as $normalPost) {
$this->push($normalPost); $this->push($normalPost);
} }
}
?> ?>
<?php while($this->next()): ?> <?php while($this->next()): ?>
<article class="post--item"> <article class="post--item">