Compare commits

..

2 Commits

Author SHA1 Message Date
浪子 0017693c81 1.2.2
增加一个随机阅读的独立页面
2025-08-02 14:29:25 +08:00
浪子 d268bd10bb 1.2.2
fix 标签
2025-08-02 14:01:18 +08:00
3 changed files with 54 additions and 15 deletions

View File

@ -65,4 +65,5 @@
- 1.2.2
- 增加侧边栏显示的全局开关
- 修复代码块中的短代码解析问题
- 修复代码块中的短代码解析问题
- 新增一个随机文章阅读的独立页面

43
page-random.php Normal file
View File

@ -0,0 +1,43 @@
<?php
/**
* 随机阅读
*
* @package custom
*/
if (!defined('__TYPECHO_ROOT_DIR__')) exit;
$db = Typecho_Db::get();
// 统计符合条件的文章总数
$countSql = $db->select('COUNT(*) AS count')
->from('table.contents')
->where('status = ?', 'publish')
->where('type = ?', 'post')
->where('created <= ?', time());
$countResult = $db->fetchRow($countSql);
$total = $countResult['count'];
if ($total > 0) {
// 随机选择一个偏移量
$offset = mt_rand(0, $total - 1);
// 根据偏移量获取一篇文章
$sql = $db->select()
->from('table.contents')
->where('status = ?', 'publish')
->where('type = ?', 'post')
->where('created <= ?', time())
->limit(1)
->offset($offset);
$result = $db->fetchRow($sql);
if (!empty($result)) {
$target = Typecho_Widget::widget('Widget_Abstract_Contents')->filter($result);
$this->response->redirect($target['permalink'], 307);
}
}
// 如果没有找到文章,重定向到首页
$this->response->redirect($this->options->siteUrl, 307);
?>

View File

@ -16,20 +16,21 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
</div>
<div id="page-tags">
<div id="page" class="row row-cols-1">
<?php if ($this->options->showsidebar): ?>
<div id="posts" class="col-lg-8 col-md-12 animated fadeInLeft">
<?php else: ?>
<div id="posts" class="col-lg-12 col-md-12">
<?php endif; ?>
<div class="puock-text p-block no-style pb-2">
<?php
// 获取所有标签
$tags = Typecho_Widget::widget('Widget_Metas_Tag_Cloud');
// 准备字母数组
$letters = range('A', 'Z');
$letters[] = '0';
$letters[] = '0';
// 获取所有存在的首字母
$existingLetters = array();
$tagsArray = array();
$tagsArray = array();
while ($tags->next()) {
$firstChar = getFirstChar($tags->name);
if (!in_array($firstChar, $existingLetters)) {
@ -41,7 +42,6 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
'count' => $tags->count
);
}
// 对每个字母下的标签按名称排序
foreach ($tagsArray as &$letterTags) {
usort($letterTags, function($a, $b) {
@ -49,7 +49,6 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
});
}
?>
<!-- 字母导航 -->
<ul class='pl-0' id='tags-main-index'>
<?php foreach ($letters as $letter): ?>
@ -63,13 +62,11 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<li class='t'><?php echo $i; ?></li>
<?php endfor; ?>
</ul>
<!-- 标签列表 -->
<ul id='tags-main-box' class='pl-0'>
<?php
// 按字母顺序排序
ksort($tagsArray);
foreach ($tagsArray as $letter => $tags): ?>
<li class='n' id='<?php echo $letter; ?>'>
<h4 class='tag-name'><span class='t-lg c-sub'>#</span><?php echo $letter; ?></h4>
@ -81,9 +78,7 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
</ul>
</div>
</div>
<?php
?>
<?php if ($this->options->showsidebar): ?>
<?php $this->need('sidebar.php'); ?>
<?php $this->need('footer.php'); ?>
<?php endif; ?>
<?php $this->need('footer.php'); ?>