2018-10-10 增加留言板博客排行功能
1、新增页面模板“留言板”- template-liuyan.php
[s][p]
<?php /* * Template Name: 留言板 * Description:留言板 */ ?> <?php get_header(); ?> <div id="primary" class="content-area"> <main id="main" class="site-main" role="main"> <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'template/content', 'page' ); ?> <div class="dh_pc"> <h3>每当在本站评论时填写网址,贵站将自动排在第一位</h3> <br> <span class="dh_more"> <a target="_blank "href="https://www.cloudcared.cn/fangke.html">更多</a> </span> <?php Autofirst(20); ?> </div> <article class="dh_title"> <h3>知名博客</h3> <br> <div class="clear"></div> <?php top_comment_authors(18); ?> </article> <?php if ( comments_open() || get_comments_number() ) : ?> <?php comments_template( '', true ); ?> <?php endif; ?> <?php endwhile; ?> </main><!-- .site-main --> </div><!-- .content-area --> <?php get_sidebar(); ?> <?php get_footer(); ?>
[/p]
2、修改inc/function.php
删除了最近访客中的头像(. get_avatar($result->comment_author_email))
3、修改functions.php
增加代码
[s][p]
//最新评论排第一 function Autofirst($af){ global $wpdb; $queryaf="select comment_author, comment_author_url, comment_date from $wpdb->comments where comment_ID in (select max(comment_ID) from $wpdb->comments where comment_approved='1' and comment_author_url !='' and user_id='0' GROUP BY comment_author_email) ORDER BY comment_date DESC LIMIT $af"; $wally = $wpdb->get_results($queryaf); foreach ($wally as $commentaf){ $tmpy= "<li class='fa fa-spinner'><a target=\"_blank\" href=\"".$commentaf->comment_author_url."\">".$commentaf->comment_author."</a></li>"; $outputy .= $tmpy; } $outputy = "<ul>".$outputy."</ul>"; echo $outputy ; }
[/p]
4、修改style.css
增加代码
[s][p]
.dh_pc { font-size: 14px; font-size: 1.4rem; height: 210px; position: relative; background: #fff; margin: 0 0 10px 0; padding: 10px 20px 10px; box-shadow: 0 0 3px #999; border-radius: 2px; } .dh_pc .dh_more { position: absolute; top: 5px; right: 20px; } .dh_pc ul li { width: 25%; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; } .dh_title h3 { font-size: 18px; margin-left: 10px; } .dh_title { background: #fff; margin: 0 0 10px 0; padding: 10px; border: 1px solid #ddd; box-shadow: 0 0 1px rgba(0,0,0,.04); border-radius: 2px; } .author-url { width: 100%; padding: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .top-comment { color: #999; text-align: center; } .top-author { background: #fff; margin: 5px; padding: 0 0 10px 0; border: 1px solid #ddd; } .top-comments .lx7 { float: left; min-height: 1px; width: 16.6666666666666%; padding: 2px; } .lx7 { float: left; min-height: 1px; width: 12.5%; padding: 2px; }
[/p]
2018-9-29 增加过期文章提示功能
1、编辑functions.php
增加代码
[s][p]
//添加老文章提示信息 function old_content_message($content) { $modified = get_the_modified_time('U'); $current = current_time('timestamp'); $diffTime = ($current - $modified) / (60 * 60 * 24); if ($diffTime > 365) { $content = '<div class="warn">本文最后更新于'.get_the_modified_time('Y年n月j日'). ',已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!</div>'.$content; } return $content; } add_filter('the_content', 'old_content_message');
[/p]
2、编辑style.css
增加代码
[s][p]
/* 提醒 */ .warn { color: #ad9948; background: #fff4b9 url(img/sc_notice.png) -1px -1px no-repeat; border: 1px solid #eac946; overflow: hidden; margin: 10px 0; padding: 15px 15px 15px 35px; font-size: 14px; }
[/p]
2018-9-6 修改站点回复邮件模板
1、备份inc/notify.php 为 inc/notify.php.bak
2、新增inc/notify.php
[s][p]
<?php // 定义界面顶部区域内容,请注意修改您的主题目录 $email_bg ='https://www.ikxin.com/wp-content/themes/lovexin/images/email.jpg'; define ('emailbg', $email_bg ); $email_headertop = ' <div class="emailpaged" style="background-image: url('.emailbg.');-webkit-background-size: cover;-moz-background-size: cover;-o-background-size: cover;background-size: cover;background-position: center center;background-repeat: no-repeat;"> <div class="emailcontent" style="width:100%;max-width:inherit;text-align: left;margin: 0 auto;padding-bottom: 20px"> <div class="emailtitle"> <h1 style="color:#fff;background: #51a0e3;line-height:70px;font-size:24px;font-weight:normal;padding-left:40px;margin:0"> '; define ('emailheadertop', $email_headertop ); $email_headerbot = ' </h1> <div class="emailtext" style="background:#fff;padding:20px 32px 40px;"> '; define ('emailheaderbot', $email_headerbot ); // 定义界面底部区域内容,请注意修改下面广告图片地址 $email_footer = ' <p style="color: #6e6e6e;font-size:13px;line-height:24px;">(此邮件由系统自动发出, 请勿回复。)</p> </div> <div class="emailad" style="margin-top: 24px;"> </div> <p style="color: #6e6e6e;font-size:13px;line-height:24px;text-align:right;padding:0 32px">邮件来自:<a href="' . get_bloginfo('url') . '" style="color:#51a0e3;text-decoration:none">' . get_option("blogname") . '</a></p> </div> </div> </div> '; define ('emailfooter', $email_footer ); // 修改网站默认发信人以及邮箱 function new_from_name($email){ $wp_from_name = get_option('blogname'); return $wp_from_name; } function new_from_email($email) { $wp_from_email = get_option('admin_email'); return $wp_from_email; } add_filter('wp_mail_from_name', 'new_from_name'); add_filter('wp_mail_from', 'new_from_email'); // 评论通过通知评论者 add_action('comment_unapproved_to_approved', 'iwill_comment_approved'); function iwill_comment_approved($comment) { if(is_email($comment->comment_author_email)) { $post_link = get_permalink($comment->comment_post_ID); // 邮件标题,可自行更改 $title = '您在 [' . get_option('blogname') . '] 的评论已通过审核'; // 邮件内容,按需更改,如果不懂改,可以给我留言 $body = emailheadertop.'留言审核通过通知'.emailheaderbot.'<p style="color: #6e6e6e;font-size:13px;line-height:24px;">您在' . get_option('blogname') . '《<a href="'.$post_link.'">'.get_the_title($comment->comment_post_ID).'</a>》发表的评论:</p> <p style="color: #6e6e6e;font-size:13px;line-height:24px;padding:10px 20px;background:#f8f8f8;margin:0px">'.$comment->comment_content.'</p> <p style="color: #6e6e6e;font-size:13px;line-height:24px;">已通过管理员审核并显示。<br /> 您可在此查看您的评论:<a href="'.get_comment_link( $comment->comment_ID ).'">前往查看</a></p>'.emailfooter; @wp_mail($comment->comment_author_email, $title, $body, "Content-Type: text/html; charset=UTF-8"); } } // 邮件评论回复美化版 function comment_mail_notify($comment_id) { $admin_email = get_bloginfo ('admin_email'); $comment = get_comment($comment_id); $comment_author_email = trim($comment->comment_author_email); $parent_id = $comment->comment_parent ? $comment->comment_parent : ''; $to = $parent_id ? trim(get_comment($parent_id)->comment_author_email) : ''; $spam_confirmed = $comment->comment_approved; if (($parent_id != '') && ($spam_confirmed != 'spam') && ($to != $admin_email)) { $wp_email = 'no-reply@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])); $subject = '您在 [' . get_option("blogname") . '] 的留言有了新回复'; $message = emailheadertop.'您在' . get_option("blogname") . '上的留言有回复啦!'.emailheaderbot.' <p style="color: #6e6e6e;font-size:13px;line-height:24px;">' . trim(get_comment($parent_id)->comment_author) . ', 您好!</p> <p style="color: #6e6e6e;font-size:13px;line-height:24px;">您在《' . get_the_title($comment->comment_post_ID) . '》的留言:<br /> <p style="color: #6e6e6e;font-size:13px;line-height:24px;padding:10px 20px;background:#f8f8f8;margin:0px">'. trim(get_comment($parent_id)->comment_content) . '</p> <p style="color: #6e6e6e;font-size:13px;line-height:24px;">' . trim($comment->comment_author) . ' 给你的回复:<br /> <p style="color: #6e6e6e;font-size:13px;line-height:24px;padding:10px 20px;background:#f8f8f8;margin:0px">'. trim($comment->comment_content) . '</p> <p style="color: #6e6e6e;font-size:13px;line-height:24px;">你可以点击<a href="' . htmlspecialchars(get_comment_link($parent_id, array('type' => 'comment'))) . '">查看完整内容</a></p> <p style="color: #6e6e6e;font-size:13px;line-height:24px;">欢迎再度光临<a href="' . get_option('home') . '">' . get_option('blogname') . '</a></p> '.emailfooter; $from = "From: \"" . get_option('blogname') . "\" <$wp_email>"; $headers = "$from\nContent-Type: text/html; charset=" . get_option('blog_charset') . "\n"; wp_mail( $to, $subject, $message, $headers ); } } add_action('comment_post', 'comment_mail_notify'); // 博客后台登录失败时发送邮件通知管理员 function wp_login_failed_notify(){ date_default_timezone_set('PRC'); $admin_email = get_bloginfo('admin_email'); $to = $admin_email; $subject = '【登录失败】有人使用了错误的用户名或密码登录' . get_bloginfo('name') . '!'; $message = emailheadertop . get_bloginfo('name') . '账户登录失败通知!'.emailheaderbot.' <div style="padding:0;font-weight:bold;color:#6e6e6e;font-size:16px">尊敬的管理员您好!</div> <p style="color: red;font-size:13px;line-height:24px;">' . get_bloginfo('name') . '有一条登录失败的记录产生,若登录操作不是您产生的,请及时注意网站安全!</p> <table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-top:1px solid #eee;border-left:1px solid #eee;color:#6e6e6e;font-size:16px;font-weight:normal"> <thead><tr><th colspan="2" style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center;background:#f8f8f8;">失败信息如下</th></tr></thead> <tbody> <tr> <td style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center;width:100px">登录名</td> <td style="padding:10px 20px 10px 30px;border-right:1px solid #eee;border-bottom:1px solid #eee;line-height:30px">' . $_POST['log'] . '</td> </tr> <tr> <td style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center">尝试的密码</td> <td style="padding:10px 20px 10px 30px;border-right:1px solid #eee;border-bottom:1px solid #eee;line-height:30px">' . $_POST['pwd'] . '</td> </tr> <tr> <td style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center;">登录时间</td> <td style="padding:10px 20px 10px 30px;border-right:1px solid #eee;border-bottom:1px solid #eee;line-height:30px">' . date("Y-m-d H:i:s") . '</td> </tr> <tr> <td style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center;">登录IP</td> <td style="padding:10px 20px 10px 30px;border-right:1px solid #eee;border-bottom:1px solid #eee;line-height:30px">' . $_SERVER['REMOTE_ADDR'] . '</td> </tr> </tbody> </table> '.emailfooter; wp_mail( $to, $subject, $message, "Content-Type: text/html; charset=UTF-8" ); } add_action('wp_login_failed', 'wp_login_failed_notify'); add_filter('logout_url', 'mk_logout_redirect_home', 10, 2); function mk_logout_redirect_home($logouturl, $redir){ $redir = home_url(); return $logouturl . '&redirect_to=' . urlencode($redir); } function user_profile_update( $user_id ) { $site_url = get_bloginfo('wpurl'); $site_name = get_bloginfo('wpname'); $user_info = get_userdata( $user_id ); $to = $user_info->user_email; $subject = "".$site_name."账户更新"; $message = emailheadertop.'您在' .$site_name. '账户资料修改成功!'.emailheaderbot.'<p style="color: #6e6e6e;font-size:13px;line-height:24px;">亲爱的 ' .$user_info->display_name . '<br/>您的资料修改成功!<br/>谢谢您的光临</p>'.emailfooter; wp_mail( $to, $subject, $message, "Content-Type: text/html; charset=UTF-8"); } add_action( 'profile_update', 'user_profile_update', 10, 2); function iwilling_delete_user( $user_id ) { global $wpdb; $site_name = get_bloginfo('name'); $user_obj = get_userdata( $user_id ); $email = $user_obj->user_email; $subject = "帐号删除提示:".$site_name.""; $message = emailheadertop.'您在' .$site_name. '的账户已被管理员删除!'.emailheaderbot.'<p style="color: #6e6e6e;font-size:13px;line-height:24px;">如果您对本次操作有什么异议,请联系管理员反馈!<br/>我们会在第一时间处理您反馈的问题.</p>'.emailfooter; wp_mail( $email, $subject, $message, "Content-Type: text/html; charset=UTF-8"); } add_action( 'delete_user', 'iwilling_delete_user' ); function newPostNotify($post_ID) { if( wp_is_post_revision($post_ID) ) return; global $wpdb; $site_name = get_bloginfo('name'); $post_contents = get_post($post_ID)->post_content; $get_post_info = get_post($post_ID); if ( $get_post_info->post_status == 'publish' && $_POST['original_post_status'] != 'publish' ) { $wp_user_email = $wpdb->get_col("SELECT DISTINCT user_email FROM $wpdb->users"); $subject = 'Hi!'.$site_name.'发布新文章啦!'; $message = emailheadertop.$site_name. '发布新文章啦!'.emailheaderbot.' <div style="padding:0;font-weight:bold;color:#6e6e6e;font-size:16px">文章标题:' . get_the_title($post_ID) . '</div> <p style="color: #6e6e6e;font-size:13px;line-height:24px;">' . mb_strimwidth($post_contents, 0, 320,"...") . '</p> <p style="color: #6e6e6e;font-size:13px;line-height:24px;text-align:right"><a href="' . get_permalink($post_ID) . '">查看全文</a><br /></p> '.emailfooter; $message_headers = "Content-Type: text/html; charset=\"utf-8\"\n"; wp_mail($wp_user_email, $subject, $message, $message_headers); } } add_action('publish_post', 'newPostNotify'); ?>
[/p]
2018-8-5 代码移除js和css的版本号显示
1、编辑functions.php
增加代码
[s][p]
/** * 移除WordPress加载的JS和CSS链接中的版本号 */ function wpdaxue_remove_cssjs_ver( $src ) { if( strpos( $src, 'ver=' ) ) $src = remove_query_arg( 'ver', $src ); return $src; } add_filter( 'style_loader_src', 'wpdaxue_remove_cssjs_ver', 999 ); add_filter( 'script_loader_src', 'wpdaxue_remove_cssjs_ver', 999 );
[/p]
2018-7-18 美化WordPress标签云样式
1、添加CSS
后台管理-外观-自定义-额外CSS
增加代码
[s][p]
.tagcloud{ padding:14px 0 14px 12px; } .tagcloud a{ float:left; margin:3px; line-height:26px; text-align:center; border:1px solid #ddd; border-radius:2px; padding-top:0; padding-right:5px; padding-bottom:0; padding-left:5px; overflow:hidden; display:block; width:92px; height:28px; } .tagcloud a{ color:#fff; }
[/p]
2、修改footer.php
增加代码
[s][p]
<script type="text/javascript">box_width = $("#cx_tag_cloud-5").width(); len = $(".tagcloud a").length - 1; $(".tagcloud a").each(function(i) { var let = new Array('3366FF', '31ac76', 'ea4563', '31a6a0', '8e7daa', '4fad7b', 'f99f13', 'f85200', '666666'); var random1 = Math.floor(Math.random() * 9) + 0; var num = Math.floor(Math.random() * 6 + 9); $(this).attr('style', 'background:#' + let[random1] + ''); if ($(this).next().length > 0) { last = $(this).next().position().left } });</script>
[/p]
2018-6-25 主题添加页面加载进度条
1、下载 pace.min.js 至目录 js下
2、修改functions.php
增加代码
[s][p]
//////// 顶部加载条 wp_enqueue_script( 'pace.min', get_theme_file_uri( '/js/pace.min.js' ), array( 'jquery' ), '1.0', true );
[/p]
3、编辑style.css
增加代码
[s][p]
.pace { -webkit-pointer-events: none; pointer-events: none; -webkit-user-select: none; -moz-user-select: none; user-select: none; } .pace-inactive { display: none; } .pace .pace-progress { background: #3690cf; position: fixed; z-index: 2000; top: 0; right: 100%; width: 100%; height: 2px; }
[/p]