wordpress主题puock

官网: https://github.com/Licoy/wordpress-theme-puock

1.增加20张头图到200张,优化头图大小不超过20k,使用了压缩:免费在线压缩JPG图像文件 (iloveimg.com)

2.原始主题文件版本 2.9.2

需要 设置的部分

主题基本设置

  • 全局设置

    • 禁止非管理员访问用户资料页
    • 禁止使用 REST API
    • 禁止使用 XML-RPC
    • 禁用Gutenberg编辑器
    • 隐藏文章浏览量
    • 隐藏底部感谢使用WordPress进行创作和左上角标识
    • 缩略图伪静态:需要设置nginx
  • 基础设置

    • 移动端侧边栏启用
    • 图片懒加载
    • 正文图片懒加载
    • 留言头像懒加载
    • 禁用正文图片灯箱预览
    • 正文内容首行缩进: 不要打开,因为标题没有缩进
    • 正文内容链接新标签页打开
    • 正文内容链接加跳转
    • 评论ajax翻页
    • 页面无刷新加载(不要打开,影响mathjax公式显示)
    • 异步浏览量统计
    • 评论相关:全部开启
    • Gravatar头像源:cravatar
  • 脚本及样式

    • 底部关于我们,底部版权说明: 关闭,删除内容

  

  • 脚本及样式

    • 底部页脚信息: 清空

外观,菜单

  • 创建菜单menu

  • :house: 首页,/

  • :man_pilot: 管理,/wp-admin/

外观,小工具

  • 删除默认

  • 通用,侧边栏

    • 文章搜索
    • 随机文章:500天内,5篇

屏蔽主题更新提示

下载安装:Disable WordPress Update Notifications and auto-update Email Notifications 插件

https://wordpress.org/plugins/disable-update-notifications/

主题已经修改,不需要设置

删除“发表至”,发表时间

single.php

删掉如下被注释的内容

                            <!--<div class="p-flex-sbc mt20 t-sm">
                                <div>
                                    <span><?php _e('发表至:', PUOCK) ?></span><?php echo get_post_category_link_exec(true) ?>
                                </div>
                                <div>
                                    <span class="c-sub"><i class="fa-regular fa-clock"></i> <?php pk_get_post_date() ?></span>
                                </div>
                            </div>-->

首页头图

准备头图,jpg 格式,按整数编号,copy 到主题目录: /var/www/html/wp-content/themes/wordpress-theme-puock-2.9.2/assets/img/random/

主题模板函数 functions.php:

function get_post_images($_post = null): string
{
    global $post;

    // 1. 获取文章对象
    $post_obj = $_post ? get_post($_post) : $post;
    if (!$post_obj) {
        return get_random_default_image();
    }

    $post_id = $post_obj->ID;
    $content = $post_obj->post_content;

    // 2. 优先:特色图(支持 attachment 和 外部链接)
    if (has_post_thumbnail($post_id)) {
        $featured_url = get_the_post_thumbnail_url($post_id, 'large');
        if ($featured_url) {
            return esc_url($featured_url);
        }
    }

    // 可选:支持外部特色图(如果你用了之前“external_thumbnail_url”的方案)
    $external_thumb = get_post_meta($post_id, 'external_thumbnail_url', true);
    if ($external_thumb) {
        return esc_url($external_thumb);
    }

    // 3. 次选:从内容提取第一张图(支持 Markdown 和 HTML)
    $first_image = null;

    // 匹配 Markdown 图片:![alt](/wp-content/uploads/url)
    if (preg_match('/!\[[^\]]*\]\(\s*([^\s\)]+?)\s*([\'"][^\'"]*?[\'"])?\s*\)/i', $content, $matches)) {
        $first_image = trim($matches[1]);
    }
    // 如果没找到 Markdown 图片,再匹配 HTML 图片
    elseif (preg_match('/<img[^>]+src=[\'"](/p/9caf0d0b5034940856ca2aac53c3183a) {
        $first_image = $matches[1];
    }

    if ($first_image && filter_var($first_image, FILTER_VALIDATE_URL)) {
        return esc_url($first_image);
    }

    // 4. 最后:返回随机默认图
    return get_random_default_image();
}

修改为:

function get_post_images($_post = null)
{
global $post;
    if ($_post != null) {
        $post = $_post;
    }
    $post_id = $post->ID;
	  $jpg_header = $post_id%199+1;
    $res = get_stylesheet_directory_uri() . '/assets/img/random/' . $jpg_header . '.jpg';
    return $res;
}

删除post列表中的分类

编辑 templates/module-post.php, 注释掉含有 <?php echo get_post_category_link( 的两条语句,并在第二个语句后添加如下代码,给移动版增加日期:

<span class="c-sub-a t-sm ml-md-2 line-h-20 d-inline-block d-md-none"><i class="fa-regular fa-clock"></i><?php pk_get_post_date() ?></span>

引用固定边框

通过增加css完成: header.php

    <style>
    blockquote {
  background: #f9f9f9;
  border: 10px solid #ccc;
  margin: 1.5em 10px;
  padding: 0.5em 10px;
}
    </style>
</head>
<body class="puock-<?php echo pk_theme_light() ? 'light' : 'dark';
echo current_theme_supports('custom-background') ? ' custom-background' : ''; ?>">

markdown代码:

> test
> $y=x^2$
> test

效果:

test
$y=x^2$
test

标题颜色为蓝色

header.php 的 style 中添加

#post-title {
    color: blue;
}
."a-link t-w-400 t-md"{
    color: blue;
}

mathjax支持

参考:

https://docs.mathjax.org/en/latest/web/start.html#configuring-mathjax

https://docs.mathjax.org/en/latest/web/configuration.html

分别修改 header.php, footer.php, 添加 mathjax配置

<!-- header 部分,在  <?php wp_head(); ?> 之前 -->
<script>
MathJax = {
  tex: {
    inlineMath: [['$', '$'], ['\\(', '\\)']]
  },
  svg: {
    fontCache: 'global'
  }
};
</script>

<!-- footer 部分 -->
<script type="text/javascript" id="MathJax-script" async
   src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js">
</script>

测试:

$\sum_{i=0}^N\int_{a}^{b}g(t, i)\text{d}t$

$\sum_{i=0}^N\int_{a}^{b}g(t, i)\text{d}t$

$$\sum_{i=0}^N\int_{a}^{b}g(t, i)\text{d}t$$

$$\sum_{i=0}^N\int_{a}^{b}g(t, i)\text{d}t$$

$\alpha+\beta=\gamma$

$$\alpha+\beta=\gamma$$

$\alpha+\beta=\gamma$

$$\alpha+\beta=\gamma$$

删除 pages/template-chatgpt.php

wordfence扫描为恶意文件

正文完
 0
评论(没有评论)