普通视图

发现新文章,点击刷新页面。
昨天以前首页
  • ✇新锐博客
  • 记一次function代码无法生效的情况莫忘
    前言 本人喜欢瞎搞,所以子主题的function.php文件中弄了不少东西,然后也就没太在意某些代码 记录 今天有人在前一篇文章进行了留言,然后我就想要回复他,突然想到之前在function中部署了关于WordPress回复他人邮件通知的功能。 但是一直没有试验有没有部署成功,因为同款主题的其他站长确定部署成功了,我就心血来潮的想要去测试一番。 于是我就在留言板回复了自己的留言,但是一直没有收到邮件,我就知道我没有部署成功。 接着,我就找到了同款主题的其他站长询问,因为安装了wpopt插件,而插件有评论站长收到邮件通知的功能。 所以自然而然就觉得是wpopt的问题了,便有了如下对话。 但是其他人都可以,为啥就我不行呢?有没有办法解决呢? 幸好现在有强大的AI,于是我就去deepseek官网,将之前的回复他人评论邮件通知的代码发给AI,并且提问为何不生效。 AI回复我可能是因为由于其他插件的缘故,导致回复他人邮件通知的功能被屏蔽掉了。于是我就想到了提高此功能的优先级。 我便让AI帮我把功能的优先级提高了。 最终有了新的代码,当然我也让AI美化了一下界面。 传送门
     

记一次function代码无法生效的情况

作者 莫忘
2025年3月13日 00:48

前言

本人喜欢瞎搞,所以子主题的function.php文件中弄了不少东西,然后也就没太在意某些代码

记录

今天有人在前一篇文章进行了留言,然后我就想要回复他,突然想到之前在function中部署了关于WordPress回复他人邮件通知的功能。

但是一直没有试验有没有部署成功,因为同款主题的其他站长确定部署成功了,我就心血来潮的想要去测试一番。

于是我就在留言板回复了自己的留言,但是一直没有收到邮件,我就知道我没有部署成功。

接着,我就找到了同款主题的其他站长询问,因为安装了wpopt插件,而插件有评论站长收到邮件通知的功能。

所以自然而然就觉得是wpopt的问题了,便有了如下对话。

图片[1]-新锐博客

但是其他人都可以,为啥就我不行呢?有没有办法解决呢?

幸好现在有强大的AI,于是我就去deepseek官网,将之前的回复他人评论邮件通知的代码发给AI,并且提问为何不生效。

AI回复我可能是因为由于其他插件的缘故,导致回复他人邮件通知的功能被屏蔽掉了。于是我就想到了提高此功能的优先级。

我便让AI帮我把功能的优先级提高了。

最终有了新的代码,当然我也让AI美化了一下界面。

传送门

  • ✇新锐博客
  • WordPress解决用户名枚举漏洞禁用REST API莫忘
    前言 今天群里有人说会通过某个地址泄露用户名导致有被爆破的风险,并且给出了解决方案 教程 首先检查一下自己的网站有没有这个漏洞,访问如下网站即可 https://博客域名.com/wp-json/wp/v2/users/ 如果有就到主题的function.php文件中添加如下代码 add_filter('rest_authentication_errors', function ($access) { return new wp_error('rest_cannot_access', 'REST API不再提供访问', ['status' => 403]); }); 此代码禁用了REST API
     

WordPress解决用户名枚举漏洞禁用REST API

作者 莫忘
2025年2月24日 02:31

前言

今天群里有人说会通过某个地址泄露用户名导致有被爆破的风险,并且给出了解决方案

教程

首先检查一下自己的网站有没有这个漏洞,访问如下网站即可

https://博客域名.com/wp-json/wp/v2/users/

如果有就到主题的function.php文件中添加如下代码

add_filter('rest_authentication_errors', function ($access) { return new wp_error('rest_cannot_access', 'REST API不再提供访问', ['status' => 403]); });

此代码禁用了REST API

  • ✇新锐博客
  • WordPress添加回复评论邮件通知莫忘
    前言 之前就想要弄这个功能了,但是主题不支持,今天果核更新了主题终于支持了 教程 将如下代码放到子主题的function.php 中即可 /** * 新评论回复邮件通知函数(带按钮,美化界面) */ function comment_mail_notify($comment_id) { // 获取评论对象 $comment = get_comment($comment_id); if (!$comment || $comment->comment_approved === 'spam') { return; // 如果评论不存在或标记为垃圾评论,直接返回 } // 获取父评论 ID $parent_id = $comment->comment_parent ? $comment->comment_parent : ''; if (empty($parent_id)) { return; // 如果没有父评论,直接返回 } // 获取父评论对象 $pa
     

WordPress添加回复评论邮件通知

作者 莫忘
2025年1月11日 00:27

前言

之前就想要弄这个功能了,但是主题不支持,今天果核更新了主题终于支持了

教程

将如下代码放到子主题的function.php 中即可

/**
 * 新评论回复邮件通知函数(带按钮,美化界面)
 */
function comment_mail_notify($comment_id) {
    // 获取评论对象
    $comment = get_comment($comment_id);
    if (!$comment || $comment->comment_approved === 'spam') {
        return; // 如果评论不存在或标记为垃圾评论,直接返回
    }

    // 获取父评论 ID
    $parent_id = $comment->comment_parent ? $comment->comment_parent : '';
    if (empty($parent_id)) {
        return; // 如果没有父评论,直接返回
    }

    // 获取父评论对象
    $parent_comment = get_comment($parent_id);
    if (!$parent_comment || empty($parent_comment->comment_author_email)) {
        return; // 如果父评论不存在或邮箱为空,直接返回
    }

    // 获取收件人邮箱
    $to = trim($parent_comment->comment_author_email);

    // 构造邮件内容
    $wp_email = 'no-reply@' . preg_replace('#^www.#', '', strtolower($_SERVER['SERVER_NAME']));
    $subject  = '您在 [' . get_option("blogname") . '] 的留言有了回复';
    $comment_link = get_comment_link($comment_id);
    $message  = '
    <div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px; border: 1px solid #e0e0e0; border-radius: 8px; background-color: #f9f9f9;">
        <h2 style="color: #333; font-size: 24px; margin-bottom: 20px;">' . trim($parent_comment->comment_author) . ', 您好!</h2>
        <p style="color: #555; font-size: 16px; line-height: 1.6;">
            您曾在文章《' . get_the_title($comment->comment_post_ID) . '》中留言:
        </p>
        <blockquote style="margin: 20px 0; padding: 10px 20px; background-color: #fff; border-left: 4px solid #0073aa; color: #666; font-style: italic;">
            ' . trim($parent_comment->comment_content) . '
        </blockquote>
        <p style="color: #555; font-size: 16px; line-height: 1.6;">
            ' . trim($comment->comment_author) . ' 给您的回复:
        </p>
        <blockquote style="margin: 20px 0; padding: 10px 20px; background-color: #fff; border-left: 4px solid #0073aa; color: #666; font-style: italic;">
            ' . trim($comment->comment_content) . '
        </blockquote>
        <p style="color: #555; font-size: 16px; line-height: 1.6; text-align: center;">
            点击下方按钮查看完整回复内容:
        </p>
        <div style="text-align: center; margin: 20px 0;">
            <a href="' . $comment_link . '" style="display: inline-block; padding: 12px 24px; font-size: 16px; color: #fff; background-color: #0073aa; border-radius: 4px; text-decoration: none;">
                查看回复
            </a>
        </div>
        <p style="color: #555; font-size: 16px; line-height: 1.6;">
            感谢您对 ' . get_option('blogname') . ' 的支持!
        </p>
        <p style="color: #999; font-size: 14px; margin-top: 20px; text-align: center;">
            此邮件由系统自动发送,请勿直接回复。
        </p>
    </div>';

    // 设置邮件头
    $headers = [
        'From: "' . get_option('blogname') . '" <' . $wp_email . '>',
        'Content-Type: text/html; charset=' . get_option('blog_charset'),
    ];

    // 发送邮件
    wp_mail($to, $subject, $message, $headers);
}

// 挂载钩子
add_action('comment_post', 'comment_mail_notify', 5, 1);
add_action('wp_insert_comment', 'comment_mail_notify', 5, 1);
  • ✇新锐博客
  • WordPress底部添加页面生成时间和数据库查询次数莫忘
    前言 今天有个群友要在网站底部添加页面生成时间和数据库查询次数,虽然wpopt插件可以实现这个功能,但是仅能管理员查看 效果图 教程 1.首先在function.php 文件中添加如下代码,有子主题可以添加到子主题中 function display_query_count_with_timer() { $query_count = get_num_queries(); $query_time = timer_stop(0, 3); $output = "<p>本次数据库查询" . $query_count . "次,页面生成花费".$query_time."秒</p>"; return $output; } add_shortcode('query_timer', 'display_query_count_with_timer'); 2.如果想添加在底部可以使用WordPress的小工具中的文本,只需要输入[query_timer] 即可。
     

WordPress底部添加页面生成时间和数据库查询次数

作者 莫忘
2024年12月5日 18:19

前言

今天有个群友要在网站底部添加页面生成时间和数据库查询次数,虽然wpopt插件可以实现这个功能,但是仅能管理员查看

效果图

图片[1]-新锐博客

教程

1.首先在function.php 文件中添加如下代码,有子主题可以添加到子主题中

function display_query_count_with_timer() {
    $query_count = get_num_queries();
    $query_time = timer_stop(0, 3);
    $output = "<p>本次数据库查询" . $query_count . "次,页面生成花费".$query_time."秒</p>";
    return $output;
}
add_shortcode('query_timer', 'display_query_count_with_timer');

2.如果想添加在底部可以使用WordPress的小工具中的文本,只需要输入[query_timer] 即可。

  • ✇新锐博客
  • WordPress利用function屏蔽搜索并且跳转到指定页面莫忘
    前言 我们平时弄网站的时候会出现各种搜索词,其中包括不少敏感词,这时候就可以使用function屏蔽某些敏感词 教程 将如下代码添加到子主题的function.php中 function block_sensitive_search_terms($query) { if ($query->is_search && !is_admin()) { $file_path = ABSPATH . '/api/minganci/blocked_terms.txt'; if (file_exists($file_path)) { $blocked_terms = file($file_path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); } else { $blocked_terms = array(); } // 获取搜索查询词 $search_query = $quer
     

WordPress利用function屏蔽搜索并且跳转到指定页面

作者 莫忘
2024年10月20日 21:41

前言

我们平时弄网站的时候会出现各种搜索词,其中包括不少敏感词,这时候就可以使用function屏蔽某些敏感词

教程

将如下代码添加到子主题的function.php中

function block_sensitive_search_terms($query) {
    if ($query->is_search && !is_admin()) {
        $file_path = ABSPATH . '/api/minganci/blocked_terms.txt';
        if (file_exists($file_path)) {
            $blocked_terms = file($file_path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
        } else {
            $blocked_terms = array();
        }
        // 获取搜索查询词
        $search_query = $query->query_vars['s'];

        // 检查搜索查询是否包含任何敏感词
        foreach ($blocked_terms as $blocked_term) {
            if (stripos($search_query, trim($blocked_term)) !== false) {
                // 跳转到404页面
                header("Location: /404");
                exit; // 确保脚本停止执行
            }
        }
    }
}
add_action('pre_get_posts', 'block_sensitive_search_terms');

其中ABSPATH . '/api/minganci/blocked_terms.txt' 是我列举的所有敏感词,你可以替换成自己的。

具体的敏感词可以访问https://www.xrbk.cn/api/minganci/blocked_terms.txt 来获取。

 

  • ✇新锐博客
  • 使用function和php实现外链跳转莫忘
    前言 之前外链跳转使用的是果核的插件,现在不想用插件了,于是自己弄了个代码 教程 首先在子主题的function.php中添加如下代码 //外链跳转 function convert_external_links_to_base64($content) { // 使用正则表达式找到所有外部链接 $pattern = '/<as+href=["'](http[s]?://[^"']+)["']/i'; $content = preg_replace_callback($pattern, function($matches) { $url = $matches[1]; // 对 URL 进行 Base64 编码 $base64_url = base64_encode($url); // 返回新的链接,指向中间页 return str_replace($url, site_url('/redirect.php?url=' . $base64_url), $matches[0]);
     

使用function和php实现外链跳转

作者 莫忘
2024年10月18日 14:41

前言

之前外链跳转使用的是果核的插件,现在不想用插件了,于是自己弄了个代码

教程

首先在子主题的function.php中添加如下代码

//外链跳转
function convert_external_links_to_base64($content) {
    // 使用正则表达式找到所有外部链接
    $pattern = '/<as+href=["'](http[s]?://[^"']+)["']/i';
    $content = preg_replace_callback($pattern, function($matches) {
        $url = $matches[1];
        // 对 URL 进行 Base64 编码
        $base64_url = base64_encode($url);
        // 返回新的链接,指向中间页
        return str_replace($url, site_url('/redirect.php?url=' . $base64_url), $matches[0]);
    }, $content);
    
    return $content;
}

// 将函数应用于文章和页面内容
add_filter('the_content', 'convert_external_links_to_base64');

再在网站根目录新建一个php文件命名为redirect.php ,并且添加如下代码

<?php
if (isset($_GET['url'])) {
    $link = base64_decode($_GET['url']);
}
?>
<!doctype html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" type="text/css" href="static/css/style.css">
    <link rel="icon" href="https://www.xrbk.cn/favicon.png" type="image/x-icon"/><!--favicon图片地址-->
    <title>新锐博客 - 安全中心</title><!--修改文字-->
</head>

<body>
  <div class="go-wild-box">
    <div class="go-wild-container">
     <a href="https://www.xrbk.cn/">
     <img alt="新锐博客" src="/wp-content/uploads/f4a9f982d722de858fd133baf4ff14b7.webp" class="logo-img" /><!--修改Logo地址-->
      </a>
     <div class="tips-title">您即将离开新锐博客,跳转到第三方链接</div><!--修改文字-->
        <div class="address"><?php echo htmlspecialchars($link); ?></div>
      <div class="tips-subtitle">请注意您的账号和财产安全</div>
      <div class="btn-groups">
        <button onclick="try { window.close(); } catch(e) { alert('请手动关闭此页面'); }" type="button" class="ant-btn ant-btn-default">取消访问</button>
        <a href="<?php echo htmlspecialchars($link); ?>" rel="nofollow">
          <button type="button" class="ant-btn ant-btn-primary">继续访问</button>
        </a>
      </div>
    </div>
  </div>
</body>
</html>
<style>
body { 
    margin: 0; font-family: 'PingFangSC', sans-serif; background-color: #EFF4FA; }
.go-wild-box { display: flex; justify-content: center; align-items: center; height: 100vh; }
.go-wild-container { width: 770px; height: 330px; max-width: 90%; padding: 90px 15px; background-color: #fff; border-radius: 12px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1); text-align: center; }
.logo-img { width: 120px; height: auto; }
.tips-title { margin: 20px 0; font-size: 22px; color: #2a3c59; font-weight: 500; }
.address { margin-bottom: 20px; padding: 15px; background-color: #EFF4FA; border-radius: 8px; color: #2a3c59; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 80%; max-width: 600px; margin: 0 auto; }
.tips-subtitle { font-size: 14px; color: #2a3c59; margin-bottom: 30px;margin-top: 20px; }
.btn-groups { display: flex; justify-content: center; gap: 10px; margin-top: 60px; }
.ant-btn { width: 152px; height: 44px; line-height: 44px; border-radius: 20px; border: none; cursor: pointer; font-size: 14px; transition: all 0.3s ease; }
.ant-btn-primary { background: linear-gradient(152deg, #07C160 0%, #07c183 100%); color: #fff; }
.ant-btn-default { background-color: #fff; color: #2a3c59; border: 1px solid #ccc; }
.ant-btn-default:hover { background-color: #fff; border-color: #07C160; color: #07C160; }
</style>

结语

这样访问文章和页面中的外部链接就可以跳转到中间页了

  • ✇新锐博客
  • WordPress侧边栏添加信息统计莫忘
    前言 刚刚写了一篇统计文章字数的文章,现在就教大家如何在侧边栏添加信息统计 教程 在子主题的function.php中添加如下代码 function display_site_stats() { // 获取统计数据 $total_posts = wp_count_posts()->publish; $site_uptime = get_site_uptime(); $last_update = get_last_update_time(); $total_word_count = get_total_word_count(); // 输出HTML $stats = [ '文章数目' => ['value' => $total_posts, 'class' => 'purple'], '存活天数' => ['value' => $site_uptime, 'class' => 'violet'], '上次更新' => ['value'
     

WordPress侧边栏添加信息统计

作者 莫忘
2024年10月4日 13:22

前言

刚刚写了一篇统计文章字数的文章,现在就教大家如何在侧边栏添加信息统计

教程

在子主题的function.php中添加如下代码

function display_site_stats() {
    // 获取统计数据
    $total_posts = wp_count_posts()->publish;
    $site_uptime = get_site_uptime();
    $last_update = get_last_update_time();
    $total_word_count = get_total_word_count();

    // 输出HTML
    $stats = [
        '文章数目' => ['value' => $total_posts, 'class' => 'purple'],
        '存活天数' => ['value' => $site_uptime, 'class' => 'violet'],
        '上次更新' => ['value' => $last_update, 'class' => 'red'],
        '文章字数' => ['value' => $total_word_count . ' 万', 'class' => 'red']
    ];

    $output = '<div style="background: #fff; padding: 10px; border-radius: 5px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);">';
    foreach ($stats as $text => $data) {
        $output .= sprintf(
            '<div style="display: flex; align-items: center; margin-bottom: 10px;">
                <span style="flex: 1;">%s</span>
                <span style="background: %s; color: #fff; padding: 2px 8px; border-radius: 12px; font-size: 0.9em;">%s</span>
            </div>',
            esc_html($text),
            esc_attr(get_badge_color($data['class'])),
            esc_html($data['value'])
        );
    }
    $output .= '</div>';

    return $output; // 返回输出的HTML
}

function get_badge_color($class) {
    switch ($class) {
        case 'purple':
            return '#9c27b0';
        case 'violet':
            return '#7e57c2';
        case 'red':
            return '#e53935';
        default:
            return '#e0e0e0';
    }
}

function get_site_uptime() {
    $start_date = new DateTime('2023-04-05'); // 替换为你的网站创建日期
    $interval = $start_date->diff(new DateTime());
    return $interval->days . '天'; // 直接返回存活的天数
}

function get_last_update_time() {
    $last_post = wp_get_recent_posts(['numberposts' => 1])[0];
    $time_difference = time() - strtotime($last_post['post_date']);

    if ($time_difference < 60) return '刚刚';
    if ($time_difference < 3600) return floor($time_difference / 60) . '分钟前';
    if ($time_difference < 86400) return floor($time_difference / 3600) . '小时前';
    return floor($time_difference / 86400) . '天前';
}

function get_total_word_count() {
    $posts = get_posts(['numberposts' => -1]);
    $total_word_count = array_sum(array_map(function($post) {
        return str_word_count(strip_tags($post->post_content));
    }, $posts));
    return round($total_word_count / 10000, 2); // 返回万字数
}

// 注册短代码
add_shortcode('xrbk-cbls', 'display_site_stats');

然后在WordPress小工具中添加文本,里面输入[xrbk-cbls]

截图

图片[1]-新锐博客

  • ✇新锐博客
  • WordPress添加所有文章内容字数统计莫忘
    前言 突发奇想,想要知道自己更新了多少字数的内容,于是就有了下面的教程。 教程 如果有子主题,请将如下代码添加到子主题的function.php中 //获取所有文章字数 function count_all_posts_word_count() { // 获取所有文章 $args = array( 'post_type' => 'post', 'posts_per_page' => -1, // 获取所有文章 ); $query = new WP_Query($args); $total_word_count = 0; // 循环遍历每篇文章 if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); // 获取文章内容 $content = get_the_content
     

WordPress添加所有文章内容字数统计

作者 莫忘
2024年10月4日 11:52

前言

突发奇想,想要知道自己更新了多少字数的内容,于是就有了下面的教程。

教程

如果有子主题,请将如下代码添加到子主题的function.php中

//获取所有文章字数
function count_all_posts_word_count() {
    // 获取所有文章
    $args = array(
        'post_type'      => 'post',
        'posts_per_page' => -1, // 获取所有文章
    );

    $query = new WP_Query($args);
    $total_word_count = 0;

    // 循环遍历每篇文章
    if ($query->have_posts()) {
        while ($query->have_posts()) {
            $query->the_post();
            // 获取文章内容
            $content = get_the_content();
            // 计算字数
            $word_count = str_word_count(strip_tags($content));
            $total_word_count += $word_count;
        }
        // 重置查询
        wp_reset_postdata();
    }

    return $total_word_count;
}

// 将字数转换为以千为单位的格式
function format_word_count($count) {
    if ($count >= 1000) {
        return round($count / 1000, 1) . 'k'; // 保留一位小数
    }
    return $count; // 小于1000的直接返回
}

// 使用短代码显示字数
function display_total_word_count() {
    $total_words = count_all_posts_word_count();
    $formatted_words = format_word_count($total_words);
    return "所有文章的总字数: " . $formatted_words;
}
add_shortcode('total_word_counts', 'display_total_word_count');
?>

然后去想要显示的地方添加[total_word_counts]

结语

如果想要添加到侧边栏的话可以使用文本小工具。

  • ✇新锐博客
  • WordPress添加彩色文本渐变框莫忘
    前言 CoreNext主题自带的编辑器增强内有标星面板,但是颜色有点少,所以找了个教程给WordPress添加彩色文本渐变框。 教程 1.首先将如下代码添加到CoreNext子主题的function.php 中,如果其他主题也有子主题一样操作。 add_action('after_wp_tiny_mce', 'bolo_after_wp_tiny_mce'); function bolo_after_wp_tiny_mce($mce_settings) { ?> <script type="text/javascript"> QTags.addButton( 'z_mhz', '迷幻紫', '<div id="zm_mhz">迷幻紫</div>n', "" ); QTags.addButton( 'z_xgh', '西瓜红', '<div id="zm_xgh">西瓜红</div>n', "" ); QTags.addButton( 'z_tkzj', '天空之境', '<div id="zm_tk
     

WordPress添加彩色文本渐变框

作者 莫忘
2024年7月4日 17:10

前言

CoreNext主题自带的编辑器增强内有标星面板,但是颜色有点少,所以找了个教程给WordPress添加彩色文本渐变框。

教程

1.首先将如下代码添加到CoreNext子主题的function.php 中,如果其他主题也有子主题一样操作。

 add_action('after_wp_tiny_mce', 'bolo_after_wp_tiny_mce');
 function bolo_after_wp_tiny_mce($mce_settings) {
 ?>
 <script type="text/javascript"> 
 QTags.addButton( 'z_mhz', '迷幻紫', '<div id="zm_mhz">迷幻紫</div>n', "" );
 QTags.addButton( 'z_xgh', '西瓜红', '<div id="zm_xgh">西瓜红</div>n', "" );
 QTags.addButton( 'z_tkzj', '天空之境', '<div id="zm_tkzj">天空之境</div>n', "" );
 QTags.addButton( 'z_xyz', '小宇宙', '<div id="zm_xyz">小宇宙</div>n', "" );
 QTags.addButton( 'z_gll', '橄榄绿', '<div id="zm_gll">橄榄绿</div>n', "" );
 QTags.addButton( 'z_xty', '小太阳', '<div id="zm_xty">小太阳</div>n', "" );
 QTags.addButton( 'z_yyz', '优雅紫', '<div id="zm_yyz">优雅紫</div>n', "" );
 QTags.addButton( 'z_szh', '深邃黑', '<div id="zm_szh">深邃黑</div>n', "" );
 QTags.addButton( 'z_wbk', '无边框', '<div id="zm_wbk">无边框</div>n', "" ); 
 function bolo_QTnextpage_arg1() {
 }
 </script>
 <?php
 }

2.将如下CSS代码添加到CoreNext子主题的CSS文件夹中的main.css中

/*渐变框区块*/
#zm_mhz,#zm_xgh,#zm_tkzj,#zm_xyz,#zm_gll ,#zm_xty,#zm_yyz,#zm_szh,#zm_wbk{
  /*圆角值,在此定义*/
  border-radius: 8px;
}
/*迷幻紫*/
#zm_mhz{
    color: #555555;
    overflow: hidden;
    margin: 10px 0;
    padding: 15px 15px 15px 35px;
    /*border-radius: 10px;*/
    box-shadow: 6px 0 12px -5px rgb(190, 196, 252), -6px 0 12px -5px rgb(189, 196, 252);
    background-color: #8EC5FC;
    background-image: linear-gradient(62deg,#8EC5FC 0%,#E0C3FC 100%);
    background-image: -webkit-linear-gradient(62deg,#8EC5FC 0%,#E0C3FC 100%);
}
/*西瓜红*/
#zm_xgh{
      color: #555555;
    overflow: hidden;
    margin: 10px 0;
    padding: 15px 15px 15px 35px;
    /*border-radius: 10px;*/
    box-shadow: 6px 0 12px -5px rgb(255, 176, 172), -6px 0 12px -5px rgb(255, 161, 174);
    background-color: #ff9a8b66;
    background-image: linear-gradient(220deg,#FF9A8B 0%,#ff6a8838 55%,#FF99AC 100%);
    background-image: -webkit-linear-gradient(220deg,#ff9a8b7a 0%,#ff6a88ab 55%,#ff99ac82 100%);
}
/*华为P30 天空之境*/
#zm_tkzj {
    color: #555555;
    overflow: hidden;
    margin: 10px 0;
    padding: 15px 15px 15px 35px;
    /*border-radius: 10px;*/
    box-shadow: 6px 0 12px -5px rgb(253, 223, 234), -6px 0 12px -5px rgb(215, 240, 243);
    background-color: #FFDEE9;
    background-image: linear-gradient(0deg,#ffdee9c4 0%,#b5fffc8f 100%);
    background-image: -webkit-linear-gradient(0deg,#ffdee9c4 0%,#b5fffc8f 100%);
}
/*小宇宙*/
#zm_xyz {
    color: #eeeeee;
    overflow: hidden;
    margin: 10px 0;
    padding: 15px 15px 15px 35px;
    /*border-radius: 10px;*/
    box-shadow: 6px 0 12px -5px rgb(12, 85, 141), -6px 0 12px -5px rgba(10, 58, 93, 0);
    background-image: radial-gradient( circle 263px at 100.2% 3%, rgba(12,85,141,1) 31.1%, rgba(205,181,93,1) 36.4%, rgba(244,102,90,1) 50.9%, rgba(199,206,187,1) 60.7%, rgba(249,140,69,1) 72.5%, rgba(12,73,116,1) 72.6% );
}
/*橄榄绿*/
#zm_gll {
    color: #eeeeee;
    overflow: hidden;
    margin: 10px 0;
    padding: 15px 15px 15px 35px;
    /*border-radius: 10px;*/
    box-shadow: 6px 0 12px -5px rgb(68, 110, 92), -6px 0 12px -5px rgb(204, 212, 163);
    background-image: linear-gradient( 102deg, rgba(68,110,92,1) 17.4%, rgba(107,156,120,1) 49.3%, rgba(154,183,130,1) 83.4%, rgba(247,237,191,1) 110.3% );
}
/*小太阳*/
#zm_xty {
    color: #ffffff;
    overflow: hidden;
    margin: 10px 0;
    padding: 15px 15px 15px 35px;
     /*border-radius: 10px; */
    box-shadow: 6px 0 12px -5px rgb(253, 223, 234), -6px 0 12px -5px rgb(215, 240, 243);
    background-image: radial-gradient( circle farthest-corner at -8.9% 51.2%, rgba(255,124,0,1) 0%, rgba(255,124,0,1) 15.9%, rgba(255,163,77,1) 15.9%, rgba(255,163,77,1) 24.4%, rgba(19,30,37,1) 24.5%, rgba(19,30,37,1) 66% );
}
/*优雅紫*/
#zm_yyz {
  color: #ffffff;
    overflow: hidden;
    margin: 10px 0;
    padding: 15px 15px 15px 35px;
    /*border-radius: 10px;*/
    box-shadow: 6px 0 12px -5px rgb(175, 160, 208), -6px 0 12px -5px rgba(177, 161, 207, 0);
    background-image: radial-gradient( circle farthest-corner at 10% 20%, rgba(95,117,227,1) 0%, rgba(188,167,205,1) 90% );
}
/*深邃黑*/
#zm_szh {
  color: #c7c7c7;
    overflow: hidden;
    margin: 10px 0;
    padding: 15px 15px 15px 35px;
    /*border-radius: 5px;*/
    box-shadow: 6px 0 12px -5px rgb(155, 170, 185), -6px 0 12px -5px rgba(177, 161, 207, 0);
    background-image: radial-gradient( circle farthest-corner at 10% 20%, rgba(0,0,0,1) 0%, rgba(64,64,64,1) 90.2% );
}
/*无边框*/
#zm_wbk {
    color: #000000;
    overflow: hidden;
    margin: 10px 0;
    padding: 15px 15px 15px 35px;
}
#zm_xyz a , #zm_gll a{
   color: #eeeeee;
}
#zm_szh a{
  color: #c7c7c7;  
}
#zm_xty a, #zm_yyz a{
  color: #ffffff;
}

3.现在就可以在编辑器内添加如下代码使用效果了。

<div id="zm_mhz">迷幻紫</div>
<div id="zm_xgh">西瓜红</div>
<div id="zm_tkzj">天空之境</div>
<div id="zm_xyz">小宇宙</div>
<div id="zm_gll">橄榄绿</div>
<div id="zm_xty">小太阳</div>
<div id="zm_yyz">优雅紫</div>
<div id="zm_szh">深邃黑</div>
<div id="zm_wbk">无边框</div>

演示

图片[1]-新锐博客

参考

原文地址:https://www.owwee.cn/post/212.html

  • ✇新锐博客
  • WordPress添加友链自助申请莫忘
    前言 闲着无聊想弄个自助申请友链的功能,这样就不弄在评论区慢慢输入网站标题等文字了。 教程 因为我是登录才能评论所以以下代码只适用登录后才能评论。 1.首先在子主题的function.php 中添加如下代码。 function display_friendlink_form() { ob_start(); ?> <style> #friendlink-form label { display: block; margin-bottom: 5px; font-weight: bold; } #friendlink-form input[type="text"], #friendlink-form input[type="url"] { width: 20%; padding: 10px; margin-bottom: 10px;
     

WordPress添加友链自助申请

作者 莫忘
2024年5月17日 00:49

前言

闲着无聊想弄个自助申请友链的功能,这样就不弄在评论区慢慢输入网站标题等文字了。

教程

因为我是登录才能评论所以以下代码只适用登录后才能评论。

1.首先在子主题的function.php 中添加如下代码。

function display_friendlink_form() {
    ob_start();
    ?>
    <style>
        #friendlink-form label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }

        #friendlink-form input[type="text"],
        #friendlink-form input[type="url"] {
            width: 20%;
            padding: 10px;
            margin-bottom: 10px;
            border: 1px solid #ccc;
            border-radius: 4px;
            box-sizing: border-box;
        }

        #friendlink-form button[type="submit"] {
            padding: 10px 20px;
            background-color: #4CAF50;
            color: #fff;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }

        #friendlink-form button[type="submit"]:hover {
            background-color: #45a049;
        }

        #friendlink-notification {
            position: fixed;
            bottom: 20px;
            right: 20px;
            background-color: #4CAF50;
            color: #fff;
            padding: 10px;
            border-radius: 4px;
            display: none;
            z-index: 9999;
        }
    </style>

    <form id="friendlink-form" method="post">
        <div>
            <label for="website-name">网站名称:<input type="text" name="website-name" id="website-name" required></label>
        </div>
        <div>
            <label for="website-description">网站描述:<input type="text" name="website-description" id="website-description" required></label>
        </div>
        <div>
            <label for="website-url">网站地址:<input type="url" name="website-url" id="website-url" required></label>
        </div>
        <div>
            <label for="website-icon">网站图标:<input type="url" name="website-icon" id="website-icon" required></label>
        </div>
        <button type="submit" id="submit-friendlink" disabled>提交</button>
    </form>

    <div id="friendlink-notification"></div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            var submitButton = document.getElementById('submit-friendlink');
            var websiteNameInput = document.getElementById('website-name');
            var websiteDescriptionInput = document.getElementById('website-description');
            var websiteUrlInput = document.getElementById('website-url');
            var websiteIconInput = document.getElementById('website-icon');

            function validateForm() {
                if (websiteNameInput.value.trim() !== '' &&
                    websiteDescriptionInput.value.trim() !== '' &&
                    websiteUrlInput.value.trim() !== '' &&
                    websiteIconInput.value.trim() !== '') {
                    submitButton.disabled = false;
                } else {
                    submitButton.disabled = true;
                }
            }

            websiteNameInput.addEventListener('input', validateForm);
            websiteDescriptionInput.addEventListener('input', validateForm);
            websiteUrlInput.addEventListener('input', validateForm);
            websiteIconInput.addEventListener('input', validateForm);

            document.getElementById('friendlink-form').addEventListener('submit', function(event) {
                event.preventDefault();

                var websiteName = websiteNameInput.value;
                var websiteDescription = websiteDescriptionInput.value;
                var websiteUrl = websiteUrlInput.value;
                var websiteIcon = websiteIconInput.value;

                var commentContent = '网站名称:' + websiteName + 'nn' +
                                     '网站描述:' + websiteDescription + 'nn' +
                                     '网站地址:' + websiteUrl + 'nn' +
                                     '网站图标:' + websiteIcon;

                var commentData = {
                    action: 'submit_friendlink',
                    websiteName: websiteName,
                    websiteDescription: websiteDescription,
                    websiteUrl: websiteUrl,
                    websiteIcon: websiteIcon,
                    post_id: <?php echo get_the_ID(); ?>,
                    user_id: <?php echo get_current_user_id(); ?>,
                };

                var xhr = new XMLHttpRequest();
                xhr.open('POST', '<?php echo admin_url('admin-ajax.php'); ?>', true);
                xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                xhr.onload = function() {
                    if (xhr.status === 200) {
                        var response = JSON.parse(xhr.responseText);
                        if (response.success) {
                            location.reload(); // 手动刷新页面
                        } else {
                            showNotification('你尚未登录请登录后重试。');
                        }
                    } else {
                        showNotification('你尚未登录请登录后重试。');
                    }
                };
                xhr.send(Object.keys(commentData).map(function(key) {
                    return encodeURIComponent(key) + '=' + encodeURIComponent(commentData[key]);
                }).join('&'));
            });
        });

        function showNotification(message) {
            var notification = document.getElementById('friendlink-notification');
            notification.textContent = message;
            notification.style.display = 'block';
            setTimeout(function() {
                notification.style.display = 'none';
            }, 2000);
        }
    </script>
    <?php
    return ob_get_clean();
}
add_shortcode('friendlink_form_new', 'display_friendlink_form');

function submit_friendlink_callback() {
    if (is_user_logged_in()) {
        $websiteName = $_POST['websiteName'];
        $websiteDescription = $_POST['websiteDescription'];
        $websiteUrl = $_POST['websiteUrl'];
        $websiteIcon = $_POST['websiteIcon'];
        $postID = $_POST['post_id'];
        $userID = $_POST['user_id'];

        if (empty($websiteName) || empty($websiteDescription) || empty($websiteUrl) || empty($websiteIcon)) {
            echo json_encode(array('success' => false));
            wp_die();
        }

        $commentData = array(
            'comment_post_ID' => $postID,
            'comment_author' => get_userdata($userID)->display_name,
            'comment_content' => "网站名称:$websiteNamenn网站描述:$websiteDescriptionnn网站地址:$websiteUrlnn网站图标:$websiteIcon",
            'comment_type' => '',
            'comment_parent' => 0,
            'user_ID' => $userID,
        );

        $commentID = wp_new_comment($commentData);
        if ($commentID) {
            echo json_encode(array('success' => true));
        } else {
            echo json_encode(array('success' => false));
        }
    } else {
        echo json_encode(array('success' => false));
    }

    wp_die();
}
add_action('wp_ajax_submit_friendlink', 'submit_friendlink_callback');
add_action('wp_ajax_nopriv_submit_friendlink', 'submit_friendlink_callback');

2.在友链页面合适的地方添加[friendlink_form_new] 短代码。

 

  • ✇新锐博客
  • WordPress搜索屏蔽所有页面莫忘
    前言 用WordPress搭建网站的站长都知道,WordPress自带的搜索路径为?s= ,这就导致搜索结果出来的时候会包含页面而不是只有文章内容,所以今天教大家如何让搜索结果屏蔽所有页面内容。 教程 我用的是CoreNext主题自带有子主题,如果没有子主题的要慎重修改。 将如下代码加到function.php 中即可 function search_filter_page($query) { if ($query->is_search) { $query->set('post_type', 'post'); } return $query; } add_filter('pre_get_posts','search_filter_page'); 测试 加代码之前的效果: 加代码之后的效果:  
     

WordPress搜索屏蔽所有页面

作者 莫忘
2024年5月5日 13:28

前言

用WordPress搭建网站的站长都知道,WordPress自带的搜索路径为?s= ,这就导致搜索结果出来的时候会包含页面而不是只有文章内容,所以今天教大家如何让搜索结果屏蔽所有页面内容。

教程

我用的是CoreNext主题自带有子主题,如果没有子主题的要慎重修改。

将如下代码加到function.php 中即可

function search_filter_page($query) {
    if ($query->is_search) {
        $query->set('post_type', 'post');
    }
    return $query;
 }
add_filter('pre_get_posts','search_filter_page');

测试

加代码之前的效果:

图片[1]-新锐博客

加代码之后的效果:

图片[2]-新锐博客

 

  • ✇新锐博客
  • WordPress添加评论邮箱通知莫忘
    前言 一直很想用评论邮件通知功能,但是一直都没有实现,今天突然有了些思路,于是就尝试一下。 截图 教程 首先下载PHPMailer邮件库,然后在function.php里添加如下代码: // 创建一个函数来发送邮件通知管理员 function send_comment_notification($comment_ID) { // 这是评论请求,执行评论邮件通知功能 // 检查是否是评论的 AJAX 请求 if (defined('DOING_AJAX') && isset($_POST['action']) && $_POST['action'] == 'add-comment') { return; // 如果是评论的 AJAX 请求,直接返回,不执行邮件发送 } // 引入PHPMailer库 require '/www/wwwroot/你的域名/PHPMailer/src/Exception.php';
     

WordPress添加评论邮箱通知

作者 莫忘
2024年4月23日 20:02

前言

一直很想用评论邮件通知功能,但是一直都没有实现,今天突然有了些思路,于是就尝试一下。

截图

图片[1]-新锐博客

教程

首先下载PHPMailer邮件库,然后在function.php里添加如下代码:

// 创建一个函数来发送邮件通知管理员
function send_comment_notification($comment_ID) {
        // 这是评论请求,执行评论邮件通知功能

        // 检查是否是评论的 AJAX 请求
        if (defined('DOING_AJAX') && isset($_POST['action']) && $_POST['action'] == 'add-comment') {
             return; // 如果是评论的 AJAX 请求,直接返回,不执行邮件发送
         }

        // 引入PHPMailer库
        require '/www/wwwroot/你的域名/PHPMailer/src/Exception.php';
        require '/www/wwwroot/你的域名/PHPMailer/src/PHPMailer.php';
        require '/www/wwwroot/你的域名/PHPMailer/src/SMTP.php';

        // 获取评论对象
        $comment = get_comment($comment_ID);

        // 获取文章对象
        $post = get_post($comment->comment_post_ID);

        // 设置管理员邮箱
        $admin_email = '收件人邮箱';

        // 创建邮件对象
        $mail = new PHPMailerPHPMailerPHPMailer;
        $mail->isSMTP();
        $mail->Host = '发件人邮箱服务器';
        $mail->SMTPAuth = true;
        $mail->Username = '发件人邮箱';
        $mail->Password = '邮箱密码';
        $mail->SMTPSecure = 'ssl';
        $mail->Port = 465;
        $mail->CharSet = 'UTF-8'; // 设置字符集为UTF-8
        $mail->setFrom('发件人邮箱', '邮箱名字');
        $mail->addAddress($admin_email);
        $mail->Subject = '有新的评论: ' . $post->post_title;
        $mail->Body = "姓名: " . $comment->comment_author . "n邮箱: " . $comment->comment_author_email . "n评论内容: " . $comment->comment_content . "nn文章链接: " . get_permalink($post);

        // 发送邮件
        if (!$mail->send()) {
            // 记录邮件发送失败状态到文件
            $log_message = date('Y-m-d H:i:s') . " - 邮件发送失败。错误信息: " . $mail->ErrorInfo . PHP_EOL;
            file_put_contents('/www/wwwroot/你的域名/PHPMailer/email_logs.txt', $log_message, FILE_APPEND);
        } else {
            // 记录邮件发送成功状态到文件
            $log_message = date('Y-m-d H:i:s') . " - 邮件已发送" . PHP_EOL;
            file_put_contents('/www/wwwroot/你的域名/PHPMailer/email_logs.txt', $log_message, FILE_APPEND);
        }
    }
// 钩子函数,当有新评论时调用send_comment_notification函数
add_action('wp_insert_comment', 'send_comment_notification');

最后在域名根目录创建一个email_logs.txt 用来记录发送记录,这样就不会影响系统对于评论成功与否的判断。

如果提示发送失败,可以尝试把ssl改成tls。

下载地址

PHPMailer
  • ✇新锐博客
  • WordPress添加追剧页面莫忘
    前言 最近看了几部电视剧,个人感觉还不错,于是想要推荐给大家,但是找了半天也没找到合适的插件或者代码,于是就自己写一个,接下来就交给大家! 效果图 教程 网站拥有子主题的朋友可以将如下代码添加到function.php中,网站没有子主题的朋友请谨慎操作! function custom_zhuiju_shortcode($atts) { $atts = shortcode_atts( array( 'url' => '', 'juming' => '', ), $atts, 'zhuiju' ); // 获取图片URL和剧名 $image_url = esc_url($atts['url']); $juming = esc_html($atts['juming']); // 输出容器的HTML $output = '<style> @media (min-wid
     

WordPress添加追剧页面

作者 莫忘
2024年4月21日 15:24

前言

最近看了几部电视剧,个人感觉还不错,于是想要推荐给大家,但是找了半天也没找到合适的插件或者代码,于是就自己写一个,接下来就交给大家!

效果图

图片[1]-新锐博客教程

网站拥有子主题的朋友可以将如下代码添加到function.php中,网站没有子主题的朋友请谨慎操作!

function custom_zhuiju_shortcode($atts) {
    $atts = shortcode_atts(
        array(
            'url' => '',
            'juming' => '',
        ),
        $atts,
        'zhuiju'
    );

    // 获取图片URL和剧名
    $image_url = esc_url($atts['url']);
    $juming = esc_html($atts['juming']);

    // 输出容器的HTML
    $output = '<style>
                @media (min-width: 768px) {
                    .zhuiju-container {
                        width: 12.5%;
                        display: inline-block;
                        text-align: center;
                        margin-bottom: 20px;
                        border: 1px solid #ccc;
                        border-radius: 10px;
                        overflow: hidden;
                    }
                }
                
                @media (max-width: 767px) {
                    .zhuiju-container {
                        width: 100%;
                        text-align: center;
                        margin-bottom: 20px;
                        border: 1px solid #ccc;
                        border-radius: 10px;
                        overflow: hidden;
                    }
                }
                </style>';

    $output .= '<div class="zhuiju-container">';
    $output .= '<img src="' . $image_url . '" class="fixed-size-image" style="width: 100%; height: 189px; display: block; pointer-events: none;" />';
    $output .= '<p style="margin:5px 0; font-size:14px;">' . $juming . '</p>';
    $output .= '</div>';

    return $output;
}
add_shortcode('zhuiju', 'custom_zhuiju_shortcode');

最后新建一个页面,再填入[zhuiju url="" juming=""] 短代码即可实现影视剧分享,以上代码能够自适应电脑端和手机端

  • ✇新锐博客
  • WordPress后台用户列表显示用户注册时间并排序莫忘
    前言 在 WordPress 后台的用户列表界面,用户是按照用户名排序的,并且没有显示注册时间,如果我们希望能够在后台看到用户的注册时间,并且按照注册时间排序,可以通过下面的步骤实现 教程 在主题的function.php 中添加如下代码,CoreNext主题添加到子主题的function.php 中。 1.在用户列表添加「注册时间」列: add_filter('manage_users_columns', function($column_headers){ $column_headers['registered'] = '注册时间'; return $column_headers; }); 2. 显示用户的「注册时间」: add_filter('manage_users_custom_column', function($value, $column_name, $user_id){ if($column_name=='registered'){ return get_date_from_gmt(get_userdata($user_id)->user_regist
     

WordPress后台用户列表显示用户注册时间并排序

作者 莫忘
2024年3月7日 19:47

前言

WordPress 后台的用户列表界面,用户是按照用户名排序的,并且没有显示注册时间,如果我们希望能够在后台看到用户的注册时间,并且按照注册时间排序,可以通过下面的步骤实现

教程

在主题的function.php 中添加如下代码,CoreNext主题添加到子主题的function.php 中。

1.在用户列表添加「注册时间」列:

add_filter('manage_users_columns', function($column_headers){
	$column_headers['registered'] = '注册时间';
	return $column_headers;
});

2. 显示用户的「注册时间」:

add_filter('manage_users_custom_column', function($value, $column_name, $user_id){
	if($column_name=='registered'){
		return get_date_from_gmt(get_userdata($user_id)->user_registered);
	}else{
		return $value;
	}
},11,3);

3. 设置「注册时间」列可以排序:

add_filter('manage_users_sortable_columns', function($sortable_columns){
	$sortable_columns['registered'] = 'registered';
	return $sortable_columns;
});

4. 默认或者使用「注册时间」排序的处理:

add_action('pre_user_query', function($query){
	if(!isset($_REQUEST['orderby']) || $_REQUEST['orderby']=='registered' ){
		if( !in_array($_REQUEST['order'],array('asc','desc')) ){
			$_REQUEST['order'] = 'desc';
		}
		$query->query_orderby = "ORDER BY user_registered ".$_REQUEST['order']."";
	}
});

上面的代码在默认的情况下,或者用户点击「用户注册」列,都按照「用户注册」进行排序。

  • ✇新锐博客
  • WordPress禁止用户在wp-admin中注册莫忘
    前言 现在很多主题都支持在前台注册用户,但是禁止任何人都可以注册就会导致前台也不能注册,所以既想前台又能注册后台不能注册,可以使用下方代码。 教程 我们可以使用跳转的方式,一旦访问链接包含wp-login.php?action=register 就直接跳转到首页。 将如下代码放到主题的function.php 中,有子主题的可以添加到子主题的function.php 中。 function disable_wp_register() { if (strpos($_SERVER['REQUEST_URI'], 'wp-login.php?action=register') !== false) { wp_redirect(home_url()); exit; } } add_action('init', 'disable_wp_register');
     

WordPress禁止用户在wp-admin中注册

作者 莫忘
2024年2月14日 00:08

前言

现在很多主题都支持在前台注册用户,但是禁止任何人都可以注册就会导致前台也不能注册,所以既想前台又能注册后台不能注册,可以使用下方代码。

教程

我们可以使用跳转的方式,一旦访问链接包含wp-login.php?action=register 就直接跳转到首页。

将如下代码放到主题的function.php 中,有子主题的可以添加到子主题的function.php 中。

function disable_wp_register() {
    if (strpos($_SERVER['REQUEST_URI'], 'wp-login.php?action=register') !== false) {
        wp_redirect(home_url()); 
        exit;
    }
}
add_action('init', 'disable_wp_register');
❌
❌