- 兼容typecho 1.3.0版本
    - 修复pjax黑暗模式下闪烁问题
    - 修复说说页面的pjax加载问题
    - 修复上一篇与下一篇文章的链接
    - 增加归属地显示设置
    - 增加系统显示设置
    - 增加浏览器信息显示设置
    - 修复pjax模式下的404跳转
This commit is contained in:
浪子 2025-07-05 12:09:23 +08:00
parent 28a72cb279
commit c7efd5abd6
13 changed files with 240 additions and 308 deletions

29
404.php
View File

@ -18,23 +18,42 @@
document.addEventListener('DOMContentLoaded', function() {
var countdown = 5; // 设置倒计时时间(秒)
var countdownElement = document.getElementById('time-count-down');
// 检查是否在 PJAX 环境中
var isPjax = typeof window.Pjax !== 'undefined' ||
(typeof jQuery !== 'undefined' && jQuery.pjax);
// 更新倒计时显示
function updateCountdown() {
countdownElement.textContent = countdown;
countdown--;
countdown--;
if (countdown < 0) {
// 倒计时结束,跳转到首页
window.location.href = "<?php $this->options->siteUrl(); ?>";
var homeUrl = "<?php $this->options->siteUrl(); ?>";
if (isPjax) {
// 使用 PJAX 方式跳转
if (typeof window.Pjax !== 'undefined') {
// 使用原生 PJAX
var pjax = new Pjax();
pjax.loadUrl(homeUrl);
} else if (typeof jQuery !== 'undefined' && jQuery.pjax) {
// 使用 jQuery PJAX
$.pjax({url: homeUrl, container: '[data-pjax-container]'});
}
} else {
// 普通跳转
window.location.href = homeUrl;
}
} else {
// 继续倒计时
setTimeout(updateCountdown, 1000);
}
}
// 开始倒计时
updateCountdown();
// 如果是 PJAX 加载,需要手动执行一些初始化
if (isPjax && typeof window.puockInit !== 'undefined') {
window.puockInit();
}
});
</script>
<?php $this->need('footer.php'); ?>

View File

@ -20,6 +20,16 @@
4. 主题部分功能需要安装插件`Puock`。项目地址: [Puock Plugin](https://github.com/jkjoy/typecho-plugin-puock)
5. 友情链接功能需要使用插件`Links`。项目地址: [Links Plugin](https://file.imsun.org/upload/2025-06/Links-1.2.7.zip),首页友情链接需要在`友链分类`中添加分类`home`。
### 主题配置
### 更新
- 全部标签页面需要启用php的 `iconv` 扩展
- 2025.07.05
- 1.1.3
- 兼容typecho 1.3.0版本
- 修复pjax黑暗模式下闪烁问题
- 修复说说页面的pjax加载问题
- 修复上一篇与下一篇文章的链接
- 增加归属地显示设置
- 增加系统显示设置
- 增加浏览器信息显示设置
- 修复pjax模式下的404跳转

View File

@ -180,10 +180,11 @@
<div class="content-text t-md mt10 puock-text">
<?php if ($comments->parent) {echo getPermalinkFromCoid($comments->parent);} $comments->content();?>
<div class="comment-os c-sub">
<?php
<?php
$deviceInfo = getBrowsersInfo($comments->agent);
$icons = getDeviceIcon($deviceInfo);
?>
<?php if (!empty($comments->options->showdevice) && $comments->options->showdevice == '1'): ?>
<!-- 系统信息 -->
<span class="mt10" title="<?php echo $deviceInfo['system'] . ' ' . $deviceInfo['systemVersion']; ?>">
<?php echo $icons['system']; ?>&nbsp;
@ -193,7 +194,8 @@
: '未知系统';
?>
</span>
<?php endif; ?>
<?php if (!empty($comments->options->showbrowsers) && $comments->options->showbrowsers == '1'): ?>
<!-- 浏览器信息 -->
<span class="mt10" title="<?php echo $deviceInfo['browser'] . ' ' . $deviceInfo['version']; ?>">
<?php echo $icons['browser']; ?>&nbsp;
@ -203,12 +205,15 @@
: '未知浏览器';
?>
</span>
<?php endif; ?>
<?php if (!empty($comments->options->showipregion) && $comments->options->showipregion == '1'): ?>
<!-- IP 地理位置 -->
<?php if($comments->ip): ?>
<span class="mt10" title="IP">
<i class="fa-solid fa-location-dot"></i>&nbsp;<?php echo get_ip_region($comments->ip); ?>
</span>
<?php endif; ?>
<?php endif; ?>
</div>
</div>
</div>

View File

@ -85,7 +85,7 @@
"home": "<?php $this->options->siteUrl(); ?>",
"use_post_menu": true,
"is_single": false,
"is_pjax": false,
"is_pjax": true,
"main_lazy_img": true,
"link_blank_open": true,
//"async_view_id": null,
@ -102,5 +102,4 @@
<script type="text/javascript" data-no-instant src="<?php $this->options->themeUrl('assets/js/puock.js'); ?>" id="puock-js"></script>
<?php $this->footer(); ?>
</body>
</html>

View File

@ -39,6 +39,18 @@ function themeConfig($form)
array('0'=> _t('否'), '1'=> _t('是')),
'0', _t('社交分享显示'), _t('选择"是"在文章页面显示社交分享。需要搭配插件使用,默认关闭'));
$form->addInput($social);
$showipregion = new Typecho_Widget_Helper_Form_Element_Radio('showipregion',
array('0'=> _t('否'), '1'=> _t('是')),
'0', _t('是否显示IP归属地'), _t('选择"是"在评论显示IP归属地。默认开启'));
$form->addInput($showipregion);
$showbrowsers = new Typecho_Widget_Helper_Form_Element_Radio('showbrowsers',
array('0'=> _t('否'), '1'=> _t('是')),
'0', _t('是否显示浏览器信息'), _t('选择"是"在评论显示浏览器信息。默认开启'));
$form->addInput($showbrowsers);
$showdevice = new Typecho_Widget_Helper_Form_Element_Radio('showdevice',
array('0'=> _t('否'), '1'=> _t('是')),
'0', _t('是否显示设备信息'), _t('选择"是"在评论显示设备信息。默认开启'));
$form->addInput($showdevice);
$gonggao = new Typecho_Widget_Helper_Form_Element_Textarea('gonggao', NULL, NULL, _t('站点公告'), _t('支持HTML'));
$form->addInput($gonggao);
$adlisttop = new Typecho_Widget_Helper_Form_Element_Textarea('adlisttop', NULL, NULL, _t('文章列表上方广告位'), _t('支持HTML'));
@ -184,129 +196,7 @@ function getPostCover($content, $cid, $fields = null) {
}
}
/**
* 获取上一篇文章
*
* @param Widget_Archive $archive 当前文章归档对象
* @return object|null 上一篇文章对象如果没有则返回null
*/
function get_previous_post($archive) {
if (!$archive->is('single')) {
return null;
}
$db = Typecho_Db::get();
$prefix = $db->getPrefix();
// 获取上一篇文章(按创建时间排序)
$post = $db->fetchRow($db->select()
->from('table.contents')
->where('table.contents.status = ?', 'publish')
->where('table.contents.created < ?', $archive->created)
->where('table.contents.type = ?', 'post')
->order('table.contents.created', Typecho_Db::SORT_DESC)
->limit(1));
if (!$post) {
return null;
}
// 构建标准化的文章对象
$result = new stdClass();
$result->cid = $post['cid'];
$result->title = $post['title'];
$result->slug = $post['slug'];
$result->created = $post['created'];
$result->content = isset($post['text']) ? $post['text'] : '';
$result->text = isset($post['text']) ? $post['text'] : '';
$result->permalink = get_permalink($post['cid']);
// 获取文章自定义字段
$fields = $db->fetchAll($db->select()->from('table.fields')
->where('cid = ?', $post['cid']));
// 添加自定义字段到文章对象
if ($fields) {
$result->fields = new stdClass();
foreach ($fields as $field) {
$result->fields->{$field['name']} = $field['str_value'] ? $field['str_value'] : $field['int_value'];
}
}
return $result;
}
/**
* 获取下一篇文章
*
* @param Widget_Archive $archive 当前文章归档对象
* @return object|null 下一篇文章对象如果没有则返回null
*/
function get_next_post($archive) {
if (!$archive->is('single')) {
return null;
}
$db = Typecho_Db::get();
$prefix = $db->getPrefix();
// 获取下一篇文章(按创建时间排序)
$post = $db->fetchRow($db->select()
->from('table.contents')
->where('table.contents.status = ?', 'publish')
->where('table.contents.created > ?', $archive->created)
->where('table.contents.type = ?', 'post')
->order('table.contents.created', Typecho_Db::SORT_ASC)
->limit(1));
if (!$post) {
return null;
}
// 构建标准化的文章对象
$result = new stdClass();
$result->cid = $post['cid'];
$result->title = $post['title'];
$result->slug = $post['slug'];
$result->created = $post['created'];
$result->content = isset($post['text']) ? $post['text'] : '';
$result->text = isset($post['text']) ? $post['text'] : '';
$result->permalink = get_permalink($post['cid']);
// 获取文章自定义字段
$fields = $db->fetchAll($db->select()->from('table.fields')
->where('cid = ?', $post['cid']));
// 添加自定义字段到文章对象
if ($fields) {
$result->fields = new stdClass();
foreach ($fields as $field) {
$result->fields->{$field['name']} = $field['str_value'] ? $field['str_value'] : $field['int_value'];
}
}
return $result;
}
/**
* 获取文章永久链接
*
* @param int $cid 文章ID
* @return string 文章链接
*/
function get_permalink($cid) {
try {
// 获取文章对象
$db = Typecho_Db::get();
$post = $db->fetchRow($db->select()
->from('table.contents')
->where('cid = ?', $cid)
->where('status = ?', 'publish'));
if (!$post) {
return '';
}
// 构造文章对象
$post['type'] = 'post'; // 确保类型为文章
$post = Typecho_Widget::widget('Widget_Abstract_Contents')->filter($post);
// 使用文章对象的 permalink 方法生成链接
return $post['permalink'] ?? '';
} catch (Exception $e) {
// 出现异常时使用最简单的方式
$options = Helper::options();
return $options->siteUrl . '?cid=' . $cid;
}
}
/**
/**
* 获取所有评论者信息的函数
*/
function getAllCommenters() {

View File

@ -4,7 +4,6 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta http-equiv='content-language' content='zh_CN'>
<title><?php $this->archiveTitle([
'category' => _t('分类 %s 下的文章'),
@ -17,10 +16,10 @@
<?php $this->options->addhead(); ?>
<style id='puock-inline-css' type='text/css'>
body {
--pk-c-primary: <?php if ($this->options->primaryColor): ?><?php $this->options->primaryColor() ?><?php else: ?>#A7E6F4<?php endif; ?>;
--pk-c-primary: <?php if ($this->options->primaryColor): ?><?php $this->options->primaryColor() ?><?php else: ?>#A7E6F4<?php endif; ?> !important;
}
:root {
--puock-block-not-tran: <?php if ($this->options->blockNotTransparent): ?><?php $this->options->blockNotTransparent() ?><?php else: ?>100<?php endif; ?>%;
--puock-block-not-tran: <?php if ($this->options->blockNotTransparent): ?><?php $this->options->blockNotTransparent() ?><?php else: ?>100<?php endif; ?>% !important;
}
</style>
<?php if ($this->options->icoUrl): ?>
@ -32,7 +31,6 @@
<!-- 通过自有函数输出HTML头部信息 -->
<?php $this->header(); ?>
</head>
<body class="puock-auto custom-background">
<div>
<div id="header-box" class="animated fadeInDown"></div>

View File

@ -4,7 +4,7 @@
*
* @package Typecho Pouck Theme
* @author 老孙博客
* @version 1.1.2
* @version 1.1.3
* @link http://www.imsun.org
*/

View File

@ -15,32 +15,28 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
</nav>
</div>
<div id="page-archives">
<div id="page" class="w-100">
<div id="posts" class="animated fadeInLeft ">
<div class="p-block puock-text">
<div class="timeline no-style">
<?php
<div id="page" class="w-100">
<div id="posts" class="animated fadeInLeft ">
<div class="p-block puock-text">
<div class="timeline no-style">
<?php
$stat = Typecho_Widget::widget('Widget_Stat');
Typecho_Widget::widget('Widget_Contents_Post_Recent', 'pageSize=' . $stat->publishedPostsNum)->to($archives);
$year = 0;
$mon = 0;
$output = '';
while ($archives->next()) {
$year_tmp = date('Y', $archives->created);
$mon_tmp = date('m', $archives->created);
$day_tmp = date('d', $archives->created);
// 检查是否需要新的时间线项目
if ($year != $year_tmp || $mon != $mon_tmp) {
// 如果不是第一个项目先关闭之前的ul
if ($year > 0 && $mon > 0) {
$output .= '</ul></div></div>';
}
}
$year = $year_tmp;
$mon = $mon_tmp;
// 开始新的时间线项目
$output .= '<div class="timeline-item">';
$output .= '<div class="timeline-location"></div>';
@ -48,19 +44,15 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
$output .= '<h4>' . $year . '-' . $mon . '</h4>';
$output .= '<ul class="pd-links pl-0">';
}
// 输出文章项
$output .= '<li><a title="' . $archives->title . '" href="' . $archives->permalink . '">';
$output .= $archives->title . '&nbsp;&nbsp;' . $day_tmp . '日&nbsp;</a></li>';
}
// 循环结束后关闭最后的标签
if ($year > 0 && $mon > 0) {
$output .= '</ul></div></div>';
}
echo $output;
?>
</div> </div> </div> </div> </div>
<?php $this->need('footer.php'); ?>
?>
</div></div></div></div></div>
<?php $this->need('footer.php'); ?>

View File

@ -14,7 +14,7 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
</ol>
</nav>
</div>
<div id="page-links">
<div id="page">
<div class="row row-cols-1">
<div id="posts" class="col-12 animated fadeInLeft ">
<div class="puock-text no-style">
@ -22,5 +22,8 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
</div>
</div>
</div>
<?php if ($this->allow('comment')): ?>
<?php $this->need('comments.php'); ?>
<?php endif; ?>
</div>
<?php $this->need('footer.php'); ?>

View File

@ -7,44 +7,28 @@
if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('header.php'); ?>
<div id="breadcrumb" class="animated fadeInUp">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a class="a-link" href="<?php $this->options->siteUrl(); ?>">首页</a></li>
<li class="breadcrumb-item active " aria-current="page"><?php $this->title() ?></li>
</ol>
</nav>
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a class="a-link" href="<?php $this->options->siteUrl(); ?>">首页</a></li>
<li class="breadcrumb-item active " aria-current="page"><?php $this->title() ?></li>
</ol>
</nav>
</div>
<div id="page-links">
<div id="page" class="row row-cols-1">
<div id="posts" class="col-12 animated fadeInLeft ">
<div class="puock-text no-style">
<div class="p-block links-main" id="page-links-217">
<h6><?php $this->title() ?></h6>
<div class="links-main-box row t-sm">
<?php
Links_Plugin::output('
<a class="link-item a-link col-lg-3 col-md-4 col-sm-6 col-6"
href="{url}"
target="_blank" rel="me" title="{name}" data-bs-toggle="tooltip">
<div class="clearfix puock-bg">
<img alt="{name}"
src="{image}"
class="lazy md-avatar"
data-src="{image}"
alt="{name}">
<div class="info">
<p class="ml-1 text-nowrap text-truncate">{name}</p>
<p class="c-sub ml-1 text-nowrap text-truncate">{title}</p>
</div>
</div>
</a>
');
?>
</div>
</div>
</div>
<div id="page-links">
<div id="page" class="row row-cols-1">
<div id="posts" class="col-12 animated fadeInLeft ">
<div class="puock-text no-style">
<div class="p-block links-main" id="page-links-217">
<h6><?php $this->title() ?></h6>
<div class="links-main-box row t-sm">
<?php Links_Plugin::output('<a class="link-item a-link col-lg-3 col-md-4 col-sm-6 col-6" href="{url}" target="_blank" rel="me" title="{name}" data-bs-toggle="tooltip"><div class="clearfix puock-bg"><img alt="{name}" src="{image}" class="lazy md-avatar" data-src="{image}" alt="{name}"><div class="info"><p class="ml-1 text-nowrap text-truncate">{name}</p><p class="c-sub ml-1 text-nowrap text-truncate">{title}</p></div></div></a>');?>
</div>
</div>
</div>
<?php $this->need('footer.php'); ?>
</div>
</div>
<?php if ($this->allow('comment')): ?>
<?php $this->need('comments.php'); ?>
<?php endif; ?>
</div>
<?php $this->need('footer.php'); ?>

View File

@ -13,7 +13,7 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<li class="breadcrumb-item active " aria-current="page"><?php $this->title() ?></li>
</ol>
</nav>
<div id="page-moments">
<div id="page-moments">
<div class="row">
<div id="posts" class="col-lg-8 col-md-12 animated fadeInLeft ">
<?php $tooot = $this->fields->tooot ? $this->fields->tooot : 'https://www.imsun.org/toot.json'; ?>
@ -21,66 +21,59 @@ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.11.5/css/lightbox.min.css" integrity="sha512-xtV3HfYNbQXS/1R1jP53KbFcU9WXiSA1RFKzl5hRlJgdOJm4OxHCWYpskm6lN0xp0XtKGpAfVShpbvlFH3MDAA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.11.5/js/lightbox.min.js" integrity="sha512-KbRFbjA5bwNan6DvPl1ODUolvTTZ/vckssnFhka5cG80JVa5zSlRPCr055xSgU/q6oMIGhZWLhcbgIC0fyw3RQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<div id="tooot"></div>
</div>
</div>
<script>
window.onload = function() {
let offset = 0; // 初始偏移量
const limit = 20; // 每次加载的数量
function fetchAndDisplayToots() {
let offset = 0;
const limit = 20;
function formatHTML(toots) {
let htmlString = '';
let htmlString = '';
toots.forEach(toot => {
// 判断是否存在 reblog
const isReblog = toot.reblog && toot.reblog.content;
const content = isReblog ? toot.reblog.content : toot.content;
const url = isReblog ? toot.reblog.url : toot.url;
const account = isReblog ? toot.reblog.account : toot.account;
const created_at = isReblog ? toot.reblog.created_at : toot.created_at;
const media_attachments = isReblog ? toot.reblog.media_attachments : toot.media_attachments;
let mediaHTML = ''; // 初始化资源相关HTML为空字符串
// 处理媒体附件
if (media_attachments.length > 0) {
let mediaHTML = '';
if (media_attachments && media_attachments.length > 0) {
media_attachments.forEach(attachment => {
if (attachment.type === 'image') {
mediaHTML += `<a href="${attachment.url}" target="_blank" data-lightbox="image-set"><img src="${attachment.preview_url}" class="thumbnail-image img" ></a>`;
}
});
}
// 使用 marked 转换 markdown 内容为 HTML
const htmlContent = marked.parse(content);
// 创建 HTML 字符串
const htmlContent = marked.parse(content || '');
htmlString += `
<div class="mb20 puock-text moments-item">
<div class="row">
<div class="col-12 col-md-1">
<div class="col-12 col-md-1">
<a class="meta ta3" href="${account.url}" target="_blank" rel="nofollow">
<div class="avatar mb10">
<img src='${account.avatar}'
class='lazy md-avatar mt-1'
data-src='${account.avatar}'
alt="${account.display_name}" title="${account.display_name}">
</div>
<div class="t-line-1 info fs12">${account.display_name}</div>
</a>
<div class="avatar mb10">
<img src='${account.avatar}'
class='lazy md-avatar mt-1'
data-src='${account.avatar}'
alt="${account.display_name}" title="${account.display_name}">
</div>
<div class="col-12 col-md-11">
<div class="p-block moment-content-box"> <span class="al"></span>
<div class="mt10 moment-content entry-content show-link-icon">
<p>${htmlContent}
</p>
<div class="resimg">${mediaHTML}</div>
</div>
<div class="mt10 moment-footer p-flex-s-right"> <span class="t-sm c-sub">
<a class="c-sub-a" href="${url}">
<span class="mr-2"><i class="fa-regular fa-clock mr-1"></i>${new Date(created_at).toLocaleString()}</span>
</a>
</span>
</div>
</div>
</div>
<div class="t-line-1 info fs12">${account.display_name}</div>
</a>
</div>
<div class="col-12 col-md-11">
<div class="p-block moment-content-box"> <span class="al"></span>
<div class="mt10 moment-content entry-content show-link-icon">
<p>${htmlContent}</p>
<div class="resimg">${mediaHTML}</div>
</div>
<div class="mt10 moment-footer p-flex-s-right"> <span class="t-sm c-sub">
<a class="c-sub-a" href="${url}">
<span class="mr-2"><i class="fa-regular fa-clock mr-1"></i>${new Date(created_at).toLocaleString()}</span>
</a>
</span>
</div>
</div>
</div>
</div>
</div>
`;
});
return htmlString;
@ -93,17 +86,26 @@ window.onload = function() {
return [];
});
}
function fetchAndDisplayToots() {
fetchToots().then(data => {
const memosContainer = document.getElementById('tooot');
const tootsToShow = data.slice(offset, offset + limit); // 选择要显示的toots
memosContainer.innerHTML += formatHTML(tootsToShow);
});
}
// 在页面加载完成后获取并展示 toots
fetchAndDisplayToots();
};
</script>
const memosContainer = document.getElementById('tooot');
if (memosContainer) memosContainer.innerHTML = '';
fetchToots().then(data => {
if (!Array.isArray(data)) {
console.error('toot.json is not an array:', data);
return;
}
const tootsToShow = data.slice(offset, offset + limit);
if (memosContainer) memosContainer.innerHTML += formatHTML(tootsToShow);
});
}
// 保证首次和 pjax 都能调用
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", fetchAndDisplayToots);
} else {
fetchAndDisplayToots();
}
document.addEventListener('pjax:end', fetchAndDisplayToots);
</script>
<style>
div pre code {
white-space: pre-wrap;
@ -161,6 +163,6 @@ img {
}
</style>
<?php $this->need('sidebar.php'); ?>
</div>
</div>
<?php $this->need('footer.php'); ?>
</div>
</div>
<?php $this->need('footer.php'); ?>

View File

@ -61,4 +61,4 @@ if($days > 180){
<?php endif; ?>
</div>
<?php $this->need('sidebar.php'); ?>
<?php $this->need('footer.php'); ?>
<?php $this->need('footer.php'); ?>

148
post.php
View File

@ -90,6 +90,7 @@ if($days > 180){
</div>
</div>
</div>
<!-- 分享海报点赞打赏 -->
<div class="mt15 post-action-panel">
<div class="post-action-content">
<div class="d-flex justify-content-center w-100 c-sub">
@ -120,69 +121,98 @@ if($days > 180){
</div>
</div>
</div>
</div> <!--内页中-->
</div>
<!--内页中-->
</div>
<?php if ($this->options->articlemid): ?>
<div class="puock-text p-block t-md ad-page-content-bottom"><?php $this->options->articlemid(); ?></div>
<?php endif; ?>
<?php $this->related(4)->to($relatedPosts); if ($relatedPosts->have()):?>
<div class="p-block pb-0">
<div class="row puock-text post-relevant">
<?php while ($relatedPosts->next()): ?>
<a href="<?php $relatedPosts->permalink(); ?>"
class="col-6 col-md-3 post-relevant-item ww">
<div
style="background:url('<?php echo getPostCover($relatedPosts->content, $relatedPosts->cid); ?>')">
<div class="title"> <?php $relatedPosts->title(); ?></div>
</div>
</a>
<?php endwhile; ?>
</div>
<?php if ($this->options->articlemid): ?>
<!--文章中广告-->
<div class="puock-text p-block t-md ad-page-content-bottom"><?php $this->options->articlemid(); ?></div>
<?php endif; ?>
<?php $this->related(4)->to($relatedPosts); if ($relatedPosts->have()):?>
<!--相关文章-->
<div class="p-block pb-0">
<div class="row puock-text post-relevant">
<?php while ($relatedPosts->next()): ?>
<a href="<?php $relatedPosts->permalink(); ?>" class="col-6 col-md-3 post-relevant-item ww">
<div style="background:url('<?php echo getPostCover($relatedPosts->content, $relatedPosts->cid); ?>')">
<div class="title"> <?php $relatedPosts->title(); ?></div>
</div>
</a>
<?php endwhile; ?>
</div>
</div>
<?php endif; ?>
<!--上一篇与下一篇-->
<div class="p-block p-lf-15">
<div class="row text-center pd-links single-next-or-pre t-md">
<div class="col-6 p-border-r-1 p-0">
<?php
// 查询上一篇(比当前文章更早的文章)
$db = Typecho_Db::get();
$prev = $db->fetchRow($db->select('cid', 'title', 'slug', 'created')
->from('table.contents')
->where('created < ?', $this->created) // 比当前文章更早
->where('type = ?', 'post') // 只查询文章,排除页面
->where('status = ?', 'publish') // 只查询已发布的
->order('created', Typecho_Db::SORT_DESC) // 按时间降序(最近的上一篇)
->limit(1));
if ($prev):
// 生成正确链接(兼容伪静态和自定义固定链接)
$prevUrl = Typecho_Router::url('post', $prev, $this->options->index);
?>
<a href="<?php echo $prevUrl; ?>" rel="prev" title="<?php echo $prev['title']; ?>">
<div class="abhl puock-text">
<p class="t-line-1"><?php echo $prev['title']; ?></p>
<span>上一篇</span>
</div>
<?php endif; ?>
<div class="p-block p-lf-15">
<div class="row text-center pd-links single-next-or-pre t-md ">
<?php $prevPost = get_previous_post($this); ?>
<div class="col-6 p-border-r-1 p-0">
<?php if ($prevPost) { ?>
<a href="<?php echo $prevPost->permalink; ?>"
rel="prev">
<div class='abhl puock-text'>
<p class='t-line-1'><?php echo $prevPost->title; ?></p>
<span>上一篇</span>
</div>
</a>
<?php } else { ?>
<a href="javascript:void(0);" rel="prev">
<div class='abhl puock-text'>
<p class='t-line-1'>没有上一篇</p>
<span>上一篇</span>
</div>
</a>
<?php } ?>
</div>
<?php $nextPost = get_next_post($this); ?>
<div class="col-6 p-0">
<?php if ($nextPost) { ?>
<a href="<?php echo $nextPost->permalink; ?>" rel="next">
<div class="abhl">
<p class="t-line-1"><?php echo $nextPost->title; ?></p>
<span>下一篇</span>
</div>
</a>
<?php } else { ?>
<a href="javascript:void(0);" rel="next">
<div class='abhl puock-text'>
<p class='t-line-1'>已是最新的文章</p>
<span>下一篇</span>
</div>
</a>
<?php } ?>
</div>
</div>
</div> <!--评论上方-->
</a>
<?php else: ?>
<a href="javascript:void(0);" rel="prev">
<div class="abhl puock-text">
<p class="t-line-1">没有上一篇</p>
<span>上一篇</span>
</div>
</a>
<?php endif; ?>
</div>
<div class="col-6 p-0">
<?php
// 查询下一篇(比当前文章更新的文章)
$next = $db->fetchRow($db->select('cid', 'title', 'slug', 'created')
->from('table.contents')
->where('created > ?', $this->created) // 比当前文章更新
->where('type = ?', 'post') // 只查询文章,排除页面
->where('status = ?', 'publish') // 只查询已发布的
->order('created', Typecho_Db::SORT_ASC) // 按时间升序(最早的下一条)
->limit(1));
if ($next):
// 生成正确链接(兼容伪静态和自定义固定链接)
$nextUrl = Typecho_Router::url('post', $next, $this->options->index);
?>
<a href="<?php echo $nextUrl; ?>" rel="next" title="<?php echo $next['title']; ?>">
<div class="abhl puock-text">
<p class="t-line-1"><?php echo $next['title']; ?></p>
<span>下一篇</span>
</div>
</a>
<?php else: ?>
<a href="javascript:void(0);" rel="next">
<div class="abhl puock-text">
<p class="t-line-1">已是最新文章</p>
<span>下一篇</span>
</div>
</a>
<?php endif; ?>
</div>
</div>
</div>
<!--评论上方-->
<?php $this->need('comments.php'); ?>
<?php if ($this->options->articlefoot): ?>
<!--文章底部广告-->
<div class="puock-text p-block t-md ad-comment-top"><?php $this->options->articlefoot(); ?></div>
<?php endif; ?>
</div>