由于有的文章是记录贴,含有相对隐秘的信息,所以要添加部分内容管理员可见,对于资源文件,为了避免太快失效,所以添加评论可见。
添加管理员可见
方法很简单,在当前网站主题下的functions.php文件中添加如下代码:
//加入部分内容隐藏
function login_to_read($atts, $content=null) {
extract(shortcode_atts(array("notice" => '
<span style="color: red;">温馨提示:</span>此处内容仅管理员可见!
'), $atts));
if ( is_user_logged_in() && !is_null( $content ) && !is_feed() )
return $content;
return $notice;
}
add_shortcode('vip', 'login_to_read');
使用时只需要在需要管理员可见的内容前后分别加入【vip】和【/vip】
即可(实际使用中要把【】换成[]),如图:
添加评论可见
方法很简单,在当前网站主题下的functions.php文件中添加如下代码:
同时记得把邮箱改成自己的邮箱
/**
* WordPress评论回复可见代码
* https://zhujicankao.com/66279.html
*/
function reply_to_read($atts, $content=null) {
extract(shortcode_atts(array("notice" => '<p class="reply-to-read">温馨提示: 此处内容需要<a href="#respond" title="评论本文">评论本文</a>后才能查看.</p>'), $atts));
$email = null;
$user_ID = (int) wp_get_current_user()->ID;
if ($user_ID > 0) {
$email = get_userdata($user_ID)->user_email;
//对博主直接显示内容
$admin_email = "xxx@xxx.com"; //博主Email
if ($email == $admin_email) {
return $content;
}
} else if (isset($_COOKIE['comment_author_email_' . COOKIEHASH])) {
$email = str_replace('%40', '@', $_COOKIE['comment_author_email_' . COOKIEHASH]);
} else {
return $notice;
}
if (empty($email)) {
return $notice;
}
global $wpdb;
$post_id = get_the_ID();
$query = "SELECT `comment_ID` FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1";
if ($wpdb->get_results($query)) {
return do_shortcode($content);
} else {
return $notice;
}
}
add_shortcode('reply', 'reply_to_read');
使用方法和前面的评论可见一样,标签内容为reply
文章按修改时间排序
默认文章是按照发布时间来进行排序的,可以改成按修改时间来进行排序
在函数模版functions.php中添加以下代码:
// sort by modify time
function order_posts_by_mod_date($orderby)
{
if (is_home() || is_archive() || is_feed())
{
$orderby = "post_modified_gmt DESC";
}
return $orderby;
}
add_filter('posts_orderby', 'order_posts_by_mod_date', 999);
bilibili插入视频优化
bilibili视频嵌入WordPress,在b站中点击分享-嵌入代码后,把代码粘贴过来,然后在allowfullscreen=”true”的后面,留1个空格,添加这段代码:
style="width: 100%; height: 500px; max-width: 100%;align:center; padding:20px 0;"
添加雪花效果
style="width: 100%; height: 500px; max-width: 100%;align:center; padding:20px 0;"
添加外部播放器
https://www.ywsj.cf/archives/wang-zhan-zhuang-xiu---gei-ni-de-wang-zhan-tian-jia-mian-fei-yin-le-bo-fang-qi
Hw1iyZy7WWQ
MqR8vhNb5fx
2S76R4TyEhq
agURxtjd9Oh
xXLYsK8bt0J
r1z3vasooFu
VZRw2Ez4oEr
fostpwZgrdv
dtWLEd5WMsb
agFzayuz3mr
u58sJpqt8Ja
Rtml5jJPfgQ
wmoUkTQm5EV
Ui7jGQzNC2N
P2mCoSIjqfn
qjvvDOSxJ42
wQL1Xke1we6
nhZ3GpEkHkl
Bvx3QPusRpM
glwelYb5foa
ZWZMttaxAcf
vuEeaKCOTad
tY3r9zKkBgj
N8ii9M0DY6i
knyp9zhX5cl
cDSlZxGtyW4
2OFOK79k1hy
5GsYlL5fdmG
VR7J3Cv4Zhn
X27q2L7ulbF
iUfzpjcfFBf
AD3wfITIlKk
8HBtI8kySvV