Wordpress建站,twenty twelve子主题修改全记录
9、修改(新增)小工具模块间边框样式
11、首页文章标题行高以及下横线
13、菜单导航样式修改并可支持svg小图标
14、添加分页导航功能并修改样式
15、设置新标签页打开链接
16、新增面包屑导航
17、标签云样式修改
18、新增返回顶部按钮
19、文章内代码部分样式修改(实现代码高亮)
20、首页和内容页的文章标题下、文章脚部添加描述元素(作者、发布时间等)并编辑样式
21、站点标题和副标题处变为logo图片(原为文字)
22、后台新增友链设置并设置样式
23、自定义aboutme和侧边栏小工具
24、在所有文章底部新增自定义固定内容(如打赏、内容版权等固定内容)
25、添加图片灯箱效果(点击图片可放大)
style.css——样式表
functions.php——函数模板
screenshot.jpg——子主题缩略图
/*
Theme Name: Twenty Twelve-child
Theme URI:https://bgbiji.com/
Description:冰哥笔记二次开发twentytwelve子主题
Author:徐雁冰
Author URI: https://bgbiji.com/
Template:twentytwelve
Version: 1.1.0
*/
@import url("../twentytwelve/style.css");
<?php
/* Function to enqueue stylesheet from parent theme */
function child_enqueue__parent_scripts() {
wp_enqueue_style( 'parent', get_template_directory_uri().'/style.css' );
}
add_action( 'wp_enqueue_scripts', 'child_enqueue__parent_scripts');
<?php
add_action( 'wp_enqueue_scripts', 'twentytwelve_enqueue_styles' );
function twentytwelve_enqueue_styles() {
$parent_style = 'parent-style'; // This is 'twentytwelve-style' for the Twenty Twelve theme.
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style ),
wp_get_theme()->get('Version')
);
}
//禁用谷歌字体
function mytheme_dequeue_fonts() {
wp_dequeue_style( 'twentytwelve-fonts' );
}
add_action( 'wp_enqueue_scripts', 'mytheme_dequeue_fonts', 11 );
/* 整体字体设置 */
body {
font-family:"Segoe UI","Microsoft YaHei","Hiragino Sans GB",STXihei,"Heiti SC",Roboto,"Droid Sans Fallback",Tahoma,Verdana,Arial,"Segoe UI Emoji",sans-serif;
font-size:100%;
font-style:inherit;
font-weight:inherit;
margin:0;
outline:0;
padding:0;
vertical-align:baseline;
}
body.custom-font-enabled {
font-family:"Segoe UI","Microsoft YaHei","Hiragino Sans GB",STXihei,"Heiti SC",Roboto,"Droid Sans Fallback",Tahoma,Verdana,Arial,"Segoe UI Emoji",sans-serif;
font-size:100%;
font-style:inherit;
font-weight:inherit;
margin:0;
outline:0;
padding:0;
vertical-align:baseline;
}
<p>
Copyright © 2019-2021
<a href="https://bgbiji.com"> 冰哥笔记 </a>|
<a href="https://bgbiji.com/sitemap.html"> 网站地图 </a>|
备案:<a href="网站备案链接" rel="external nofollow" target="_blank">这里填你的网站备案号</a> |
<a target="_blank" href="公网安备号链接" style="display:inline-block;text-decoration:none;height:20px;line-height:20px;">
<img src="https://bgbiji.com/wp-content/uploads/2019/07/beian.png" style="float:left;"/> 这里写公网安备号</a>
<br>虽然辛苦,我还是会选择那种滚烫的人生!任何反馈和建议,欢迎联系我。<br>
我的微博:<a href="https://weibo.com/5214143450/profile?topnav=1&wvr=6" rel="external nofollow" target="_blank">徐雁冰</a> | 公众号:冰哥笔记
</p>
/* 页脚设置 */
footer[role="contentinfo"] {
margin: 24px 0 0 0;
text-align: left;
max-width: 1190px;
max-width: 85rem;
font-size: 13px;
padding: 28px 0 28px 0;
}
/* 网页宽度 */
.site {
margin: 0 auto;
max-width: 1190px;
max-width: 85rem;
overflow: auto;
}
/* 网页头部和底部间距 */
body .site {
margin-top: 0;
margin-bottom: 0;
}
//添加截取摘要汉字字数为200个
function custom_excerpt_length( $length ) {
return 200;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
//为摘要添加继续阅读字样
// Remove the ... from excerpt and change the text
function change_excerpt_more()
{
function new_excerpt_more($more)
{
// Use .read-more to style the link
return ' [......]<span class="read-more"> <a href="' . get_permalink($post->ID) . '"><br/><br/>继续阅读»»»</a></span>';
}
add_filter('excerpt_more', 'new_excerpt_more');
}
add_action('after_setup_theme', 'change_excerpt_more');
<?php if ( is_search() ) : // Only display excerpts for search. ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
<?php if ( is_search() || is_category() || is_archive() || is_home() ) : //Display Excerpts for Search category archive home ?>
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-summary -->
//去除分类标志代码
add_action( 'load-themes.php', 'no_category_base_refresh_rules');
add_action('created_category', 'no_category_base_refresh_rules');
add_action('edited_category', 'no_category_base_refresh_rules');
add_action('delete_category', 'no_category_base_refresh_rules');
function no_category_base_refresh_rules() {
global $wp_rewrite;
$wp_rewrite -> flush_rules();
}
add_action('init', 'no_category_base_permastruct');
function no_category_base_permastruct() {
global $wp_rewrite, $wp_version;
if (version_compare($wp_version, '3.4', '<')) {
// For pre-3.4 support
$wp_rewrite -> extra_permastructs['category'][0] = '%category%';
} else {
$wp_rewrite -> extra_permastructs['category']['struct'] = '%category%';
}
}
// Add our custom category rewrite rules
add_filter('category_rewrite_rules', 'no_category_base_rewrite_rules');
function no_category_base_rewrite_rules($category_rewrite) {
//var_dump($category_rewrite); // For Debugging
$category_rewrite = array();
$categories = get_categories(array('hide_empty' => false));
foreach ($categories as $category) {
$category_nicename = $category -> slug;
if ($category -> parent == $category -> cat_ID)// recursive recursion
$category -> parent = 0;
elseif ($category -> parent != 0)
$category_nicename = get_category_parents($category -> parent, false, '/', true) . $category_nicename;
$category_rewrite['(' . $category_nicename . ')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$'] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
$category_rewrite['(' . $category_nicename . ')/page/?([0-9]{1,})/?$'] = 'index.php?category_name=$matches[1]&paged=$matches[2]';
$category_rewrite['(' . $category_nicename . ')/?$'] = 'index.php?category_name=$matches[1]';
}
// Redirect support from Old Category Base
global $wp_rewrite;
$old_category_base = get_option('category_base') ? get_option('category_base') : 'category';
$old_category_base = trim($old_category_base, '/');
$category_rewrite[$old_category_base . '/(.*)$'] = 'index.php?category_redirect=$matches[1]';
//var_dump($category_rewrite); // For Debugging
return $category_rewrite;
}
// Add 'category_redirect' query variable
add_filter('query_vars', 'no_category_base_query_vars');
function no_category_base_query_vars($public_query_vars) {
$public_query_vars[] = 'category_redirect';
return $public_query_vars;
}
// Redirect if 'category_redirect' is set
add_filter('request', 'no_category_base_request');
function no_category_base_request($query_vars) {
//print_r($query_vars); // For Debugging
if (isset($query_vars['category_redirect'])) {
$catlink = trailingslashit(get_option('home')) . user_trailingslashit($query_vars['category_redirect'], 'category');
status_header(301);
header("Location: $catlink");
exit();
}
return $query_vars;
}
/* 修改首页文章模块间边框样式 */
.site-content article {
border: 1px solid #ededed;
padding: 24px;
margin-bottom: 24px;
overflow: auto;
}
/* 修改(新增)小工具模块间边框样式 */
.widget-area .widget {
border: 1px solid #ededed;
padding: 24px;
margin-bottom: 24px;
}
/* 小工具标题字体样式以及下横线 */
.widget-title {
font-size: 18px;
font-weight: normal;
color: #21759b;
border-bottom: 1px solid #ededed;
}
/* 首页文章标题行高以及下横线 */
.entry-header .entry-title {
line-height: 2.181818182;
border-bottom: 1px solid #ededed;
}
<div class="header-search"><?php get_search_form(); ?></div><!--网站头部添加搜索框-->
/* 头部添加搜索框 */
.header-search {
float: right;
margin-top: -50px;
}
@media (max-width: 650px) {
.header-search {
display: none;
}
}
/* 只限于导航字体修改 */
.main-navigation .current_page_item > a {
font-size: 16px;
letter-spacing: 2px;
font-style: normal;
font-weight: 500;
}
/* 导航首页行高与外边距修改 */
.main-navigation li a {
line-height: 50px;
margin-left: 5px;
margin-right: 5px;
}
/* 导航其余菜单行高与外边距修改 */
.main-navigation li {
font-size: 16px;
letter-spacing: 2px;
font-style: normal;
font-weight: 400;
margin-left: 20px;
margin-right: 20px;
}
/* 导航下拉菜单字体与背景修改 */
.main-navigation li ul li a {
background: #76aac1;
border-bottom: 2px solid #fff;
font-size: 1rem;
width: 8rem;
color: #fff;
}
/* 导航下拉菜单外边距修改 */
.main-navigation li ul li {
margin-left: -10px;
margin-right: 0;
}
<!-- font-awesome图标 -->
<link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<i class="fa fa-home"></i>
<?php twentytwelve_content_nav( 'nav-below' ); ?>
<!--设置新的分页导航-->
<div class="posts-nav">
<ul>
<?php echo paginate_links(array(
'prev_next' => 1,
'before_page_number' => '',
'mid_size' => 2,
));?>
<ul>
</div>
<!--设置完毕-->
/* 分页导航样式 */
.posts-nav {
font-size:14px;
color:rgba(0, 0, 0, 0.44);
padding:10px 0;
margin:0 auto;
text-align:center;
}
.posts-nav .page-numbers {
border-radius:3px;
border:1px solid rgba(0, 0, 0, 0.15);
display:inline-block;
text-align:center;
width:30px;
line-height:30px;
margin:0 5px;
}
.posts-nav .page-numbers.current, .posts-nav .page-numbers:not(.dots):hover {
background:#3b5998;
border-color:#3b5998;
color:#fff;
}
.posts-nav .page-numbers.dots {
border-color:rgba(0, 0, 0, 0);
}
a.prev.page-numbers, a.next.page-numbers {
border-radius:3px;
border:1px solid rgba(0, 0, 0, 0.15);
display:inline-block;
text-align:center;
width:70px;
line-height:30px;
margin:0 5px;
}
<base target="_blank">
面包屑导航这个概念来自童话故事“汉赛尔和格莱特”,当汉赛尔和格莱特穿过森林时,不小心迷路了,但是他们发现在沿途走过的地方都撒下了面包屑,让这些面包屑来帮助他们找到回家的路。所以,面包屑导航的作用是告诉访问者他们目前在网站中的位置以及如何返回。
// 面包屑导航
function breadcrumb() {
// Check if is front/home page, return
if ( is_front_page() ) {
return;
}
// Define
global $post;
$custom_taxonomy = ''; // If you have custom taxonomy place it here
$defaults = array(
'seperator' => ' / ',
'id' => 'breadcrumb',
'classes' => 'breadcrumb',
'home_title' => esc_html__( '⚐ Home', '' )
);
$sep = '<li class="seperator">'. esc_html( $defaults['seperator'] ) .'</li>';
// Start the breadcrumb with a link to your homepage
echo '<ul id="'. esc_attr( $defaults['id'] ) .'" class="'. esc_attr( $defaults['classes'] ) .'">';
// Creating home link
echo '<li class="item"><a href="'. get_home_url() .'">'. esc_html( $defaults['home_title'] ) .'</a></li>' . $sep;
if ( is_single() ) {
// Get posts type
$post_type = get_post_type();
// If post type is not post
if( $post_type != 'post' ) {
$post_type_object = get_post_type_object( $post_type );
$post_type_link = get_post_type_archive_link( $post_type );
echo '<li class="item item-cat"><a href="'. $post_type_link .'">'. $post_type_object->labels->name .'</a></li>'. $sep;
}
// Get categories
$category = get_the_category( $post->ID );
// If category not empty
if( !empty( $category ) ) {
// Arrange category parent to child
$category_values = array_values( $category );
$get_last_category = end( $category_values );
// $get_last_category = $category[count($category) - 1];
$get_parent_category = rtrim( get_category_parents( $get_last_category->term_id, true, ',' ), ',' );
$cat_parent = explode( ',', $get_parent_category );
// Store category in $display_category
$display_category = '';
foreach( $cat_parent as $p ) {
$display_category .= '<li class="item item-cat">'. $p .'</li>' . $sep;
}
}
// If it's a custom post type within a custom taxonomy
$taxonomy_exists = taxonomy_exists( $custom_taxonomy );
if( empty( $get_last_category ) && !empty( $custom_taxonomy ) && $taxonomy_exists ) {
$taxonomy_terms = get_the_terms( $post->ID, $custom_taxonomy );
$cat_id = $taxonomy_terms[0]->term_id;
$cat_link = get_term_link($taxonomy_terms[0]->term_id, $custom_taxonomy);
$cat_name = $taxonomy_terms[0]->name;
}
// Check if the post is in a category
if( !empty( $get_last_category ) ) {
echo $display_category;
echo '<li class="item item-current">'. get_the_title() .'</li>';
} else if( !empty( $cat_id ) ) {
echo '<li class="item item-cat"><a href="'. $cat_link .'">'. $cat_name .'</a></li>' . $sep;
echo '<li class="item-current item">'. get_the_title() .'</li>';
} else {
echo '<li class="item-current item">'. get_the_title() .'</li>';
}
} else if( is_archive() ) {
if( is_tax() ) {
// Get posts type
$post_type = get_post_type();
// If post type is not post
if( $post_type != 'post' ) {
$post_type_object = get_post_type_object( $post_type );
$post_type_link = get_post_type_archive_link( $post_type );
echo '<li class="item item-cat item-custom-post-type-' . $post_type . '"><a href="' . $post_type_link . '">' . $post_type_object->labels->name . '</a></li>' . $sep;
}
$custom_tax_name = get_queried_object()->name;
echo '<li class="item item-current">'. $custom_tax_name .'</li>';
} else if ( is_category() ) {
$parent = get_queried_object()->category_parent;
if ( $parent !== 0 ) {
$parent_category = get_category( $parent );
$category_link = get_category_link( $parent );
echo '<li class="item"><a href="'. esc_url( $category_link ) .'">'. $parent_category->name .'</a></li>' . $sep;
}
echo '<li class="item item-current">'. single_cat_title( '', false ) .'</li>';
} else if ( is_tag() ) {
// Get tag information
$term_id = get_query_var('tag_id');
$taxonomy = 'post_tag';
$args = 'include=' . $term_id;
$terms = get_terms( $taxonomy, $args );
$get_term_name = $terms[0]->name;
// Display the tag name
echo '<li class="item-current item">'. $get_term_name .'</li>';
} else if( is_day() ) {
// Day archive
// Year link
echo '<li class="item-year item"><a href="'. get_year_link( get_the_time('Y') ) .'">'. get_the_time('Y') . '年</a></li>' . $sep;
// Month link
echo '<li class="item-month item"><a href="'. get_month_link( get_the_time('Y'), get_the_time('m') ) .'">'. get_the_time('M') .'</a></li>' . $sep;
// Day display
echo '<li class="item-current item">'. get_the_time('jS') .' '. get_the_time('M'). '</li>';
} else if( is_month() ) {
// Month archive
// Year link
echo '<li class="item-year item"><a href="'. get_year_link( get_the_time('Y') ) .'">'. get_the_time('Y') . '年</a></li>' . $sep;
// Month Display
echo '<li class="item-month item-current item">'. get_the_time('M') .'</li>';
} else if ( is_year() ) {
// Year Display
echo '<li class="item-year item-current item">'. get_the_time('Y') .'年</li>';
} else if ( is_author() ) {
// Auhor archive
// Get the author information
global $author;
$userdata = get_userdata( $author );
// Display author name
echo '<li class="item-current item">'. 'Author: '. $userdata->display_name . '</li>';
} else {
echo '<li class="item item-current">'. post_type_archive_title() .'</li>';
}
} else if ( is_page() ) {
// Standard page
if( $post->post_parent ) {
// If child page, get parents
$anc = get_post_ancestors( $post->ID );
// Get parents in the right order
$anc = array_reverse( $anc );
// Parent page loop
if ( !isset( $parents ) ) $parents = null;
foreach ( $anc as $ancestor ) {
$parents .= '<li class="item-parent item"><a href="'. get_permalink( $ancestor ) .'">'. get_the_title( $ancestor ) .'</a></li>' . $sep;
}
// Display parent pages
echo $parents;
// Current page
echo '<li class="item-current item">'. get_the_title() .'</li>';
} else {
// Just display current page if not parents
echo '<li class="item-current item">'. get_the_title() .'</li>';
}
} else if ( is_search() ) {
// Search results page
echo '<li class="item-current item">Search results for: '. get_search_query() .'</li>';
} else if ( is_404() ) {
// 404 page
echo '<li class="item-current item">' . 'Error 404' . '</li>';
}
// End breadcrumb
echo '</ul>';
}
<?php
// 文章页面添加面包屑导航
if ( function_exists('breadcrumb') ) breadcrumb();
?>
/* 面包屑导航样式 */
.breadcrumb {
font-size: 12px;
color: #888;
margin:0 auto;
}
.breadcrumb a {
color: #888;
}
.breadcrumb a:not(.dots):hover {
color: #CC0033;
}
.breadcrumb li {
display: inline;
line-height:20px;
}
/* 标签云样式修改 */
.tagcloud {
overflow:hidden;
line-height:20px;
}
.tagcloud a {
font-size: 13px!important;
border:1px solid rgba(0, 0, 0, 0.3);
padding:5px;
margin-right:5px;
margin-bottom:4px;
float:left;
display:block;
}
.tagcloud a:not(.dots):hover {
background-color: #336699;
color: #FFFFFF;
border:0;
}
<!-- 返回顶部 -->
<div style="display: none;" id="gotop"></div>
<script type='text/javascript'> backTop=function (btnId){ var btn=document.getElementById(btnId); var d=document.documentElement; var b=document.body; window.onscroll=set; btn.onclick=function (){ btn.style.display="none"; window.onscroll=null; this.timer=setInterval(function(){ d.scrollTop-=Math.ceil((d.scrollTop+b.scrollTop)*0.1); b.scrollTop-=Math.ceil((d.scrollTop+b.scrollTop)*0.1); if((d.scrollTop+b.scrollTop)==0) clearInterval(btn.timer,window.onscroll=set); },10); }; function set(){btn.style.display=(d.scrollTop+b.scrollTop>300)?'block':"none"} }; backTop('gotop');
</script>
<!-- 返回顶部END -->
/* 返回顶部 */
@media (min-width: 960px) {
#gotop{
width:40px;
height:40px;
position:fixed;
bottom:130px;
right:30px;
top:auto;
display:block;
cursor:pointer;
background: url(images/top.svg) no-repeat center center;
}
*html #gotop{
position:absolute;
bottom:auto;
top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)));
}
}
/* 文章内代码块样式修改 */
.entry-content code {
display: block;
font-size: 13px;
line-height: 30px;
overflow-x: auto;
white-space: pre;
word-wrap: normal;
border-radius: 4px;
padding: 8px;
color: #d4d4d4;
background: #214555;
}
<?php if ( is_single() ) : ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php else : ?>
<p class="meta"><!--文章页标题下标签-->
Auth:<?php the_author_nickname(); ?>      
Date:<?php echo the_time('Y/m/j'); ?>      
Cat:<?php the_category('、'); ?>
</p>
<?php if ( comments_open() ) : ?>
<div class="comments-link">
<?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'twentytwelve' ) . '</span>', __( '1 Reply', 'twentytwelve' ), __( '% Replies', 'twentytwelve' ) ); ?>
</div><!-- .comments-link -->
<?php endif; // comments_open() ?>
<?php if ( is_single() ) : ?>
<footer class="content-foot"><!--文章页脚部显示修改-->
<?php the_tags('⚑Tags:','、'); ?>      
</footer><!-- .content-foot -->
<?php else : ?>
<footer class="home-foot"><!--除文章页脚部显示修改-->
◷<?php echo the_time('Y/m/j'); ?>  
@<?php the_author_nickname(); ?>  
▤<?php the_category('、'); ?>  
⚑<?php the_tags('','、'); ?>
<?php edit_post_link( __( '——编辑', 'twentytwelve-child' ), '<span class="edit-link">', '</span>' ); ?>
</footer><!-- .entry-meta -->
<?php endif; // is_single() ?>
/* 文章页标题、meta块、和脚部样式修改 */
#content .title {
font-size: 24px;
padding-bottom: 24px;
text-align: center;
}
#content .meta {
font-size: 13px;
padding: 10px 0 10px 0;
border: 1px dashed rgba(0, 0, 0, 0.15);
text-align: center;
letter-spacing: 0.035rem;
}
#content .content-foot {
font-size: 13px;
padding: 10px 0 10px 24px;
margin: 0 -24px -24px -24px;
letter-spacing: 0.035rem;
background-color: #ededed;
}
/* 首页文章meta标签样式 */
#content .home-foot {
margin-top: 24px;
margin-top: 1.714285714rem;
font-size: 13px;
font-size: 0.928571429rem;
line-height: 1.846153846;
color: #757575;
}
<hgroup>
<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
<h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
</hgroup>
<hgroup>
<h1 class="site-title">
<a href="https://bgbiji.com" title="冰哥笔记" rel="home">
<img src="https://bgbiji.com/wp-content/uploads/2021/04/headerlogo.png" alt="冰哥笔记" width="200" height="70" />
</a><!--站点标题和副标题变为图片logo-->
</hgroup>
//调取友链
add_filter('pre_option_link_manager_enabled','__return_true');
//只显示在首页
function bgbj_friend_links($output){
if (!is_home()|| is_paged()){
$output = "";
}
return $output;
}
add_filter('wp_list_bookmarks','bgbj_friend_links');
/* 友链样式(分两栏) */
.blogroll{
display: block;
overflow: auto;
zoom: 1;
}
.blogroll li{
float: left;
width: 50%;
display: block;
}
<?php
/**
* Template Name: 自定义页面模板
*/
?>
<?php
/**
* Template Name: 自定义页面模板
*/
get_header();?>
<?php get_footer(); ?>
<?php
/**
* Template Name: BG Page Template
*
* Description: A page template that provides a key component of WordPress as a CMS
* by meeting the need for a carefully crafted introductory page. The BG page template
* in Twenty Twelve consists of a page content area for adding text, images, video --
* anything you'd like -- followed by bg-page-only widgets in one or two columns.
*
* @package WordPress
* @subpackage Twenty_Twelve
* @since Twenty Twelve 1.0
*/
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php
while ( have_posts() ) :
the_post();
?>
<?php get_template_part( 'content', 'page' ); ?>
<?php comments_template( '', true ); ?>
<?php endwhile; // End of the loop. ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar( 'front' ); ?>
<?php get_footer(); ?>
<?php get_sidebar(); ?>
<?php get_sidebar( 'front' ); ?>
//在所有文章底部添加自定义内容
function bgbj_add_after_post_content($content) {
if(!is_feed() && !is_home() && is_singular('post') && is_main_query()) {
$content .= '
这个区域可以随便写内容
';
}
return $content;
}
add_filter('the_content', 'bgbj_add_after_post_content', 99, 1);
//在所有文章底部添加自定义内容
function bgbj_add_after_post_content($content) {
if(!is_feed() && !is_home() && is_singular('post') && is_main_query()) {
$content .= '
<br/><br/>
<div style="text-align: center; letter-spacing: 1px;">
<strong><span style="font-size: 24px;color: #333333;">Thank you.</span></strong><br/>
<span style="color: #565656;">If you like my content, please let me know : )</span><br/><br/>
<i class="fa fa-angle-down" aria-hidden="true"></i><br/>
<i class="fa fa-angle-down" aria-hidden="true"></i><br/>
<i class="fa fa-angle-down" aria-hidden="true"></i>
</div><br/>
<div style="text-align: center; border-top: 1px solid #ededed;">
<br/><br/>
<div>
<strong>用 <span style="color: #339966;">微信</span> OR <span style="color: #337fe5;">支付宝</span> 扫描二维码</strong>
</div>
<div>
<strong>为作者 <span style="color: #ff6600;">打个赏</span></strong>
</div>
<br/>
<div>
<img class="wp-image-558 size-thumbnail" src="https://bgbiji.com/wp-content/uploads/2021/04/shoukuan.png" alt="pay" width="500" height="278" />
</div>
<div>
<span style="color: #999999;letter-spacing:2px;">金额随意 感谢支持</span>
</div>
<br/><br/>
</div>
';
}
return $content;
}
add_filter('the_content', 'bgbj_add_after_post_content', 99, 1);
/**图片灯箱效果(点击放大)**/
add_filter('the_content', 'fancybox');
function fancybox($content){
$pattern = array("/<img(.*?)src=('|\")([^>]*).(bmp|gif|jpeg|jpg|png|swf)('|\")(.*?)>/i","/<a(.*?)href=('|\")([^>]*).(bmp|gif|jpeg|jpg|png|swf)('|\")(.*?)>(.*?)<\/a>/i");
$replacement = array('<a$1href=$2$3.$4$5 data-fancybox="gallery"><img$1src=$2$3.$4$5$6></a>','<a$1href=$2$3.$4$5 data-fancybox="images"$6>$7</a>');
$content = preg_replace($pattern, $replacement, $content);
return $content;
}
<!-- 图片灯箱放大 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css" />
<!-- 图片灯箱放大 -->
<script src="https://cdn.jsdelivr.net/gh/fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js"></script>
<nav class="nav-single">
<nav class="nav-single">
<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3>
<span class="nav-previous"><?php previous_post_link( '%link', '<span class="meta-nav">' . _x( '←', 'Previous post link', 'twentytwelve' ) . '</span>上一篇:%title' ); ?></span>
<span class="nav-next"><?php next_post_link( '%link', '下一篇:%title <span class="meta-nav">' . _x( '→', 'Next post link', 'twentytwelve' ) . '</span>' ); ?></span>
</nav><!-- .nav-single -->
/* 单篇文章页文章下的“上一篇和下一篇”样式修改 */
.site-content nav {
padding: 16px;
background-color: #ededed;
}
//禁用自动保存
function no_autosave() {
wp_deregister_script('autosave');
}
add_action( 'wp_print_scripts', 'no_autosave' );
//禁用所有文章类型的修订版本
add_filter( 'wp_revisions_to_keep', 'bgbj_wp_revisions_to_keep', 10, 2 );
function bgbj_wp_revisions_to_keep( $num, $post ) { return 0;}
add_action('publish_post', 'refresh_front_page', 0); //发布或者更新日志时候刷新首页
add_action('delete_post', 'refresh_front_page', 0); //删除日志时候刷新首页
//隐藏版本号
function wpbeginner_remove_version() {
return '';
}
add_filter('the_generator', 'wpbeginner_remove_version');
// 头像设置
function get_ssl_avatar($avatar) {
$avatar = preg_replace('/.*\/avatar\/(.*)\?s=([\d]+)&.*/','<img src="https://dn-qiniu-avatar.qbox.me/avatar/" class="avatar avatar-$2" height="44" width="44">',$avatar);
return $avatar;
}
add_filter('get_avatar', 'get_ssl_avatar');
4、在做修改之前,请记得做好备份,如果修改的不满意,或者出了一些问题,也可以及时恢复。另外,我强烈建议大家用本地搭建的方式来修改调试,这可以避免很多不必要的损失。
赞 (0)