handsome主题美化(持续更新)
一、版本与使用说明
本站使用的主题版本为 Handsome 8.2.1 Pro。
本文整理了主题文件的作用,以及消息提示、文章版权、自定义样式等修改示例。
修改前请备份
部分设置涉及主题源码修改。建议先备份原文件,再按需添加代码。
示例中的作者、QQ、网址等信息,请根据实际情况替换。
如有疑问,欢迎在评论区交流。
二、主题文件说明
页面布局
header.php:页面头部。headnav.php:顶部导航。aside.php:左侧导航栏。sidebar.php:右侧栏目。footer.php:页面底部,包含版权信息、音乐播放器等内容。
文章与评论
index.php:网站首页。post.php:文章内容输出。page.php:独立页面模板。comments.php:评论区。
功能页面
archive.php:内容整合页面。files.php:归档页面。booklist.php:书单页面。cross.php:时光机页面。say.php:时光机动态。guestbook.php:留言板。links.php:友情链接。404.php:404 页面。
主题功能
functions.php:主题功能与设置相关代码。
三、自定义 JavaScript
以下示例包含三项功能:
- 网站加载完成提示。
- 复制成功提示。
- 复制文章时自动附加版权信息。
使用说明
示例调用了
$、$.message()和notie()。使用前,请确认页面已加载对应脚本。第二项与第三项都包含复制提示,同时启用时可能出现重复提示,请按需选择。
1. 网站加载完成提示
显示网站加载完成的消息,并在存在来源页面时显示来源地址。
/* 网站加载完成提示开始 */
function kaygb_referrer() {
var kaygb_referrer = document.referrer;
if (kaygb_referrer != "") {
return "感谢您的访问! 您来自:<br>" + document.referrer;
} else {
return "";
}
}
$.message({
message: "为了网站的正常运行,请不要使用广告屏蔽插件,谢谢!<br>" + kaygb_referrer(),
title: "网站加载完成",
type: "success",
autoHide: !1,
time: "3000"
});
/* 网站加载完成提示结束 */2. 复制成功提示
监听页面的复制操作,提示访客转载时注明出处。
/* 复制成功提示开始 */
kaygb_copy();
function kaygb_copy() {
$(document).ready(function () {
$("body").bind("copy", function (e) {
hellolayer();
});
});
var sitesurl = window.location.href;
function hellolayer() {
$.message({
message: "尊重原创,转载请注明出处!<br>本文作者:瑞哲ovo<br>原文链接:" + sitesurl,
title: "复制成功",
type: "warning",
autoHide: !1,
time: "5000"
});
}
}
/* 复制成功提示结束 */3. 复制文章时自动附加版权信息
当复制内容超过 42 个字符 时,在复制内容中附加作者、来源及版权说明。
请先替换代码中的以下信息:
- 作者名称:
瑞哲ovo - 联系 QQ:
2290294443 - 来源网址:
http://www.ruizheovo.com/
/* 复制文章自动附加版权信息开始 */
document.body.addEventListener("copy", function (e) {
if (
window.getSelection().toString() &&
window.getSelection().toString().length > 42
) {
setClipboardText(e);
notie({
type: "info",
text: "商业转载请联系作者获得授权,非商业转载请注明出处,谢谢合作。",
autoHide: true
});
}
});
function setClipboardText(event) {
var clipboardData = event.clipboardData || window.clipboardData;
if (clipboardData) {
event.preventDefault();
var htmlData = ""
+ "著作权归作者所有。<br>"
+ "商业转载请联系作者获得授权,非商业转载请注明出处!<br>"
+ "本博转载文章版权及解释权归原作者所有,博主只是勤劳的搬运工!<br>"
+ "作者:瑞哲ovo QQ:2290294443<br>"
+ "链接:" + window.location.href + "<br>"
+ "来源:http://www.ruizheovo.com/<br><br>"
+ window.getSelection().toString();
var textData = ""
+ "著作权归作者所有。\n"
+ "商业转载请联系作者获得授权,非商业转载请注明出处!\n"
+ "本博转载文章版权及解释权归原作者所有,博主只是勤劳的搬运工!\n"
+ "作者:瑞哲ovo QQ:2290294443\n"
+ "链接:" + window.location.href + "\n"
+ "来源:http://www.ruizheovo.com/\n\n"
+ window.getSelection().toString();
clipboardData.setData("text/html", htmlData);
clipboardData.setData("text/plain", textData);
}
}
/* 复制文章自动附加版权信息结束 */四、文章底部版权声明
添加位置
编辑 Handsome 主题中的 post.php,将以下代码添加到文章正文结束后的合适位置。
原示例参考位置约为第 96 行。不同版本或修改后的文件行号可能不同,请以正文实际结束位置为准。
版权声明代码
<!-- 版权声明开始 -->
<div class="entry-content l-h-2x">
<div style="padding: 10px; background: rgba(220, 220, 220, 0.22); font-size: 13px; border-left: 3px solid; text-align: left;">
<span>
本文作者:
<a href="<?php $this->author->permalink(); ?>" rel="author"><?php $this->author(); ?></a>
<br>
</span>
<span>
文章标题:
<a href="<?php $this->permalink(); ?>"><?php $this->title(); ?></a>
<br>
</span>
<span>
本文地址:
<a href="<?php $this->permalink(); ?>"><?php $this->permalink(); ?></a>
<br>
</span>
<span>
版权说明:若无注明,本文皆
<a href="<?php $this->options->siteUrl(); ?>" target="_blank" data-original-title="<?php $this->options->title(); ?>"><?php $this->options->title(); ?></a>
原创,转载请保留文章出处。
</span>
</div>
</div>
<!-- 版权声明结束 -->五、自定义 CSS
添加位置
进入主题设置,依次找到:
开发者设置 → 自定义 CSS
将需要使用的样式添加到对应输入框中,并保存设置。
1. 文章标题及底部图标居中
/* 文章标题居中 */
.panel h2 {
text-align: center;
}
.panel-small h2 {
text-align: center;
}
.panel-picture h3 {
text-align: center;
}
/* 文章底部图标居中 */
.post-item-foot-icon {
text-align: center;
}2. 全站黑白模式
以下为原示例中的黑白模式样式,按需添加。
/* 开启黑白模式 */
html {
-webkit-filter: grayscale(100%);
filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
}六、页面加载动画
代码完整性说明
原始内容在加载动画部分被截断,仅提供了样式,缺少完整的动画 HTML 结构,以及加载结束后隐藏遮罩的处理逻辑。
以下保留已有样式供整理参考,尚不能作为完整的加载动画直接部署。
已提供的动画样式
原示例计划将相关代码添加到 header.php 中。
<!-- 加载动画样式开始 -->
<style>
#PageLoading {
background-color: #fff;
height: 100%;
width: 100%;
position: fixed;
z-index: 1;
margin-top: 0;
top: 0;
}
#PageLoading-center {
width: 100%;
height: 100%;
position: relative;
}
#PageLoading-center-absolute {
position: absolute;
left: 50%;
top: 50%;
height: 200px;
width: 200px;
margin-top: -100px;
margin-left: -100px;
}
.object2 {
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
border-radius: 50%;
position: absolute;
border-left: 5px solid #ffb6c1;
border-right: 5px solid #b6def7;
border-top: 5px solid transparent;
border-bottom: 5px solid transparent;
-webkit-animation: animate 2s infinite;
animation: animate 2s infinite;
}
#object_one {
left: 75px;
top: 75px;
width: 50px;
height: 50px;
}
#object_two {
left: 65px;
top: 65px;
width: 70px;
height: 70px;
-webkit-animation-delay: 0.1s;
animation-delay: 0.1s;
}
#object_three {
left: 55px;
top: 55px;
width: 90px;
height: 90px;
-webkit-animation-delay: 0.2s;
animation-delay: 0.2s;
}
#object_four {
left: 45px;
top: 45px;
width: 110px;
height: 110px;
-webkit-animation-delay: 0.3s;
animation-delay: 0.3s;
}
@-webkit-keyframes animate {
50% {
-ms-transform: rotate(180deg);
-webkit-transform: rotate(180deg);
transform: rotate(180deg);
}
100% {
-ms-transform: rotate(0deg);
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
}
@keyframes animate {
50% {
-ms-transform: rotate(180deg);
-webkit-transform: rotate(180deg);
transform: rotate(180deg);
}
100% {
-ms-transform: rotate(0deg);
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
}
</style>
<!-- 加载动画样式结束 -->