惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
宝玉的分享
宝玉的分享
Jina AI
Jina AI
Martin Fowler
Martin Fowler
W
WeLiveSecurity
V
Vulnerabilities – Threatpost
GbyAI
GbyAI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Privacy International News Feed
D
DataBreaches.Net
Security Archives - TechRepublic
Security Archives - TechRepublic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Scott Helme
Scott Helme
U
Unit 42
Hacker News - Newest:
Hacker News - Newest: "LLM"
Google DeepMind News
Google DeepMind News
酷 壳 – CoolShell
酷 壳 – CoolShell
Vercel News
Vercel News
I
InfoQ
N
Netflix TechBlog - Medium
罗磊的独立博客
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
IT之家
IT之家
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
T
Tailwind CSS Blog
S
Securelist
S
Schneier on Security
T
Troy Hunt's Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cisco Blogs
H
Hacker News: Front Page
Spread Privacy
Spread Privacy
T
Tenable Blog
博客园 - Franky
Apple Machine Learning Research
Apple Machine Learning Research
Recent Commits to openclaw:main
Recent Commits to openclaw:main
D
Darknet – Hacking Tools, Hacker News & Cyber Security
博客园_首页
量子位
AI
AI
L
LINUX DO - 最新话题
J
Java Code Geeks
小众软件
小众软件
爱范儿
爱范儿
月光博客
月光博客
H
Help Net Security
aimingoo的专栏
aimingoo的专栏

李锋镝的博客

LiteLLM 本地代理搭建 Claude-HUD 使用文档 Kratos+ —— Kratos 主题二次开发记录 译文:如何将单体应用拆解为微服务 codebase-memory-mcp 极简完整使用指南 Claude Haiku 4.5、Claude Sonnet 4.6、Claude Opus 4.7 区别以及各自的新特性 SchedulingConfigurer详解 踩坑60+次后,我终于搞懂 Claude Skill 怎么写才会真的触发 Everything Claude Code 详细使用文档 配置Jackson使用字段而不是getter/setter来序列化和反序列化 这个域名注册整整十年了,十年时间,真快啊 Claude Code全维度实战指南:从入门到精通,解锁AI编程新范式 Apollo配置中心中的protalDB的作用是什么 org.apache.ibatis.plugin.Interceptor类详细介绍及使用 岁末 Excel2016右键新建工作表,打开时提示“因为文件格式或文件扩展名无效。请确定文件未损坏,并且文件扩展名与文件的格式匹配。”的解决办法 玩博客的人是不是越来越少了? Java 为什么有这么多 “O”? 别再背线程池的七大参数了,现在面试官都这么问 2024年11月1号 农历十月初一 我的第一个WordPress插件:Dylan Custom Plugin上线了 推荐一款比较养眼的Xshell配色方案 hnswlib installation failed 开工啦~ 阳了... MybatisCodeHelperPro激活 @Async注解的坑 新买的笔记本发货啦…… 这个中秋节感觉过的好累啊 IDEA下载源码报:Cannot connect to the Maven process. Try again later. RocketMQ的push消费方式实现详解 看病难~取药难~~ 笑死、腹肌……根本不可能有腹肌的~~ 居家办公了~ C# 11 的这个新特性,我愿称之最强! IntelliJ IDEA 2020.3.x永久白嫖(Windows/Mac) IDEA无限试用方法【2020.3最新亲测有效】 SpringBoot使用注解的方式构建Elasticsearch查询语句,实现多条件的复杂查询 UUID太长怎么办?快来试试NanoId 忽然发现,在校大学生可以免费领一年有道云笔记会员~ 醒醒~补个税了 使用itext和freemarker来根据Html模板生成PDF文件,加水印、印章 来来来,用python画一个冰墩墩儿 SpringBoot整合GraphQL入门教程 办理居住证困难重重啊! 妈呀,昨天晚上睡觉做了一晚上的梦,可累死我了 感觉Typecho很简洁啊…… WordPress的自动更新好烦啊 BeanCopier工具类(性能优化工具类) 内存屏障浅析 居住证可算是申请通过了…… 试了下壁挂炉供暖 关于重阳节 居住证签注... Spring Boot 2.x使用PostgreSQL数据库 十一节后开工头一天,修了个耳机…… 玉楼春·尊前拟把归期说 nginx反向代理配置去除前缀 1931→2021! Navicat Premium数据库账号密码解密 百度的索引量数据现在有点儿太夸张了吧? 哇塞~这个小姐姐实在太惊艳了…… 关于8月29号下午博客故障的一些记录 如何形象的描述反应式编程中的背压(Backpressure)机制? 基于Java8的Either类 海琴烟~~~ JMX监控权限认证配置 IntelliJ IDEA 2019.3.3 永久激活 破解[Windows] SpringBoot整合Elasticsearch详细步骤以及代码示例(附源码) SpringBoot整合Elasticsearch游标查询(scroll) GitLab创建新项目,初次提交命令和流程 吐槽下Google浏览器~ 从零搭建Spring Cloud Gateway网关(一) 从零搭建Spring Cloud Gateway网关(二)—— 打印请求响应日志 博客有logo啦 你的答案 数据库事务的一点简单总结 Spring Boot发展史(Spring Boot介绍) 【漫画】戏说外行对程序员的误会有多深 【收藏】从面试官角度观察到的程序员技能瓶颈,同时给出突破瓶颈的建议 Git中.gitignore文件不起作用的解决办法 背影 - 朱自清 jmap命令(jdk1.8) 彻底搞懂mysql日志系统binlog,redolog,undolog 出院了~~~ linux中ftp查看不到文件列表的问题 PHP版本怎么更新啊…… 成语接龙 StarUML4.0破解文件 Java SPI详解 WordPress评论框增加自定义表情 因在公司上不正经网站,我没过试用期… 优化了MYSQL大量写入问题,老板奖励了1000块给我 不慌不忙的坚强(林徽因39段最美文字!) ConcurrentHashMap常用方法源码解析(jdk1.8) 我是如何失去团队掌控的? HBASE填坑日志 关闭apache httpclient4.5 DEBUG日志 使用OpenShift搭建k8s集群 SonarQube Scanner的配置与使用简介
wordpress增加说说功能
李锋镝 · 2025-10-23 · via 李锋镝的博客

后台添加说说模块

首先我们把以下代码,添加到主题根目录中的functions.php文件中。下面两步代码安装完成后,在后台页面,建立微语页面,在设置菜单,保存首页导航栏即可。

function create_shuoshuo_post_type() {
    $labels = array(
        'name'               => '说说',
        'singular_name'      => '说说',
        'menu_name'          => '说说',
        'name_admin_bar'     => '说说',
        'add_new'            => '新增说说',
        'add_new_item'       => '新增一条说说',
        'new_item'           => '新说说',
        'edit_item'          => '编辑说说',
        'view_item'          => '查看说说',
        'all_items'          => '所有说说',
        'search_items'       => '搜索说说',
        'not_found'          => '未找到说说',
        'not_found_in_trash' => '回收站中未找到说说'
    );

    $args = array(
        'labels'             => $labels,
        'public'             => true,
        'has_archive'        => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_rest' => true,
        'show_in_menu'       => true,
        'query_var'          => true,
        'rewrite'            => array('slug' => 'shuoshuo'),
        'capability_type'    => 'post',
        'hierarchical'       => false,
        'menu_position'      => 5,
        'supports'           => array('title', 'editor', 'author', 'comments')
    );

    register_post_type('shuoshuo', $args);
}
add_action('init', 'create_shuoshuo_post_type');

前端模版页面

在模板主题根目录新建一个名为page-shuo.php的文件,并将以下代码添加在其中:

<?php

/**
 * Template Name: 说说/微语
 */

get_header();
?>
<!-- 引入 jQuery 库 -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
    /* 页面整体背景色,选择莫兰迪色系的浅灰色 */
    body {
        background-color: #f5f5f0;
    }

    body.theme-dark .cbp_tmtimeline::before {
        background: RGBA(255, 255, 255, 0.06)
    }

    ul.cbp_tmtimeline {
        padding: 0
    }

    div.cbp_tmlabel > li .cbp_tmlabel {
        margin-bottom: 0
    }

    .cbp_tmtimeline {
        margin: 30px 0 0 0;
        padding: 0;
        list-style: none;
        position: relative
    }

    .cbp_tmtimeline > li .cbp_tmtime {
        display: block;
        max-width: 70px;
        position: absolute
    }

    .cbp_tmtimeline > li .cbp_tmtime span {
        display: block;
        text-align: right
    }

    .cbp_tmtimeline > li .cbp_tmtime span:first-child {
        font-size: 0.9em;
        color: #888888; /* 莫兰迪色系的深灰色 */
    }

    .cbp_tmtimeline > li .cbp_tmtime span:last-child {
        font-size: 1.2em;
        color: #759375; /* 莫兰迪色系的绿色 */
    }

    .cbp_tmtimeline > li:nth-child(odd) .cbp_tmtime span:last-child {
        color: RGBA(255, 125, 73, 0.75)
    }

    div.cbp_tmlabel > p {
        margin-bottom: 0
    }

    /* 调整列表项与头像的间距 */
   .cbp_tmtimeline > li .cbp_tmlabel {
        margin: 0 0 45px 75px; /* 减少左边距,拉近与头像的距离 */
        padding: 1.2em 1.5em;
        font-weight: 300;
        line-height: 1.6;
        position: relative;
        border-radius: 10px;
        transition: all 0.3s ease 0s;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); /* 更柔和的阴影效果 */
        cursor: pointer;
        display: block;
    }

    .cbp_tmlabel:hover {
        transform: translateY(-3px);
        z-index: 1;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15); /* 悬停时更明显的阴影效果 */
    }

    /* 调整箭头的位置 */
   .cbp_tmtimeline > li .cbp_tmlabel:after {
        right: 100%;
        border: solid transparent;
        content: " ";
        height: 0;
        width: 0;
        position: absolute;
        pointer-events: none;
        border-width: 10px;
        top: 20px; /* 调整箭头的垂直位置 */
    }

    p.shuoshuo_time {
        margin-top: 15px;
        border-top: 1px dashed #ccc; /* 莫兰迪色系的浅灰色线条 */
        padding-top: 8px;
        font-family: 'Playfair Display', serif; /* 更具艺术感的字体 */
        font-size: 0.9em;
        color: #888888;
    }

    @media screen and (max-width:65.375em) {
        .cbp_tmtimeline > li .cbp_tmtime span:last-child {
            font-size: 1.2em
        }
    }

    .shuoshuo_author_img img {
        border: 2px solid #fff;
        padding: 2px;
        float: left;
        border-radius: 50%;
        transition: all 1.0s;
        height: 60px;
        margin-right: 15px;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }

    .avatar {
        -webkit-border-radius: 100% !important;
        -moz-border-radius: 100% !important;
        box-shadow: inset 0 -1px 0 #3333sf;
        -webkit-box-shadow: inset 0 -1px 0 #3333sf;
        -webkit-transition: 0.4s;
        -webkit-transition: -webkit-transform 0.4s ease-out;
        transition: transform 0.4s ease-out;
        -moz-transition: -moz-transform 0.4s ease-out
    }

    .zhuan {
        transform: rotateZ(720deg);
        -webkit-transform: rotateZ(720deg);
        -moz-transform: rotateZ(720deg)
    }

    /* 定义更多不同的莫兰迪色系背景颜色,增加多样性 */
   .cbp_tmtimeline > li:nth-child(6n + 1) .cbp_tmlabel {
        background-color: #e0c6d2;
    }

   .cbp_tmtimeline > li:nth-child(6n + 2) .cbp_tmlabel {
        background-color: #c8d5e0; /* 浅蓝色 */
    }

   .cbp_tmtimeline > li:nth-child(6n + 3) .cbp_tmlabel {
        background-color: #d2e0c6; /* 浅绿色 */
    }

   .cbp_tmtimeline > li:nth-child(6n + 4) .cbp_tmlabel {
        background-color: #e0d2c6; /* 浅橙色 */
    }

   .cbp_tmtimeline > li:nth-child(6n + 5) .cbp_tmlabel {
        background-color: #d2c6e0; /* 浅紫色 */
    }

   .cbp_tmtimeline > li:nth-child(6n) .cbp_tmlabel {
        background-color: #c6d2e0; /* 浅蓝绿色 */
    }

   .cbp_tmtimeline > li:nth-child(6n + 1) .cbp_tmlabel:after {
        border-right-color: #e0c6d2;
    }

   .cbp_tmtimeline > li:nth-child(6n + 2) .cbp_tmlabel:after {
        border-right-color: #c8d5e0;
    }

   .cbp_tmtimeline > li:nth-child(6n + 3) .cbp_tmlabel:after {
        border-right-color: #d2e0c6;
    }

   .cbp_tmtimeline > li:nth-child(6n + 4) .cbp_tmlabel:after {
        border-right-color: #e0d2c6;
    }

   .cbp_tmtimeline > li:nth-child(6n + 5) .cbp_tmlabel:after {
        border-right-color: #d2c6e0;
    }

   .cbp_tmtimeline > li:nth-child(6n) .cbp_tmlabel:after {
        border-right-color: #c6d2e0;
    }

    /* 调整字体样式 */
   .cbp_tmtimeline > li .cbp_tmlabel p {
        margin-bottom: 8px;
        font-family: 'Playfair Display', serif; /* 更具艺术感的字体 */
    }

    /* 增加间距 */
   .cbp_tmtimeline > li {
        margin-bottom: 30px;
    }

    /* 移动端样式调整 */
    @media screen and (max-width: 768px) {
       .cbp_tmtimeline > li .cbp_tmlabel {
            margin: 0 0 30px 60px; /* 进一步减少左边距 */
            padding: 1em 1.2em; /* 减少内边距 */
        }

       .cbp_tmtimeline > li .cbp_tmlabel:after {
            border-width: 8px; /* 缩小箭头尺寸 */
            top: 15px; /* 调整箭头垂直位置 */
        }

        p.shuoshuo_time {
            font-size: 0.8em; /* 缩小时间字体大小 */
        }
    }
</style>

<div id="primary" class="content-area" style="width:100%">
    <main id="main" class="site-main" role="main">
        <div class="cbp_shuoshuo">
            <?php
            $paged = (get_query_var('paged'))? get_query_var('paged') : 1;
            // 使用 WP_Query 代替 query_posts
            $args = array(
                'post_type' =>'shuoshuo',
                'post_status' => 'publish',
                'posts_per_page' => 20,
                'paged' => $paged
            );
            $query = new WP_Query($args);
            $total_pages = $query->max_num_pages;
            if ($query->have_posts()) : ?>
                <ul class="cbp_tmtimeline" id="shuoshuo-list">
                    <?php
                    while ($query->have_posts()) : $query->the_post(); ?>
                        <li>
                            <span class="shuoshuo_author_img"><?php echo get_avatar(get_the_author_meta('ID'), 60); ?></span>
                            <a class="cbp_tmlabel" href="javascript:void(0)">
                                <p><?php the_content(); ?></p>
                                <p class="shuoshuo_time"><i class="fa fa-clock-o"></i> <?php the_time('Y年n月j日G:i'); ?></p>
                            </a>
                        </li>
                    <?php endwhile;
                    wp_reset_postdata(); // 重置查询
                    ?>
                </ul>
                <?php
                if ($total_pages > 1) {
                    $big = 999999999; // 需要一个不太可能的整数
                    echo '<div class="pagination">';
                    echo paginate_links(array(
                        'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
                        'format' => '?paged=%#%',
                        'current' => max(1, $paged),
                        'total' => $total_pages
                    ));
                    echo '</div>';
                }
                ?>
            <?php
            else : ?>
                <h3 style="text-align: center;">你还没有发表说说噢!</h3>
                <p style="text-align: center;">赶快去发表你的第一条说说心情吧!</p>
            <?php
            endif; ?>
        </div>
    </main><!-- #main -->
</div><!-- #primary -->
<script type="text/javascript">
    $(function () {
        var oldClass = "";
        var Obj = "";
        $(".cbp_tmtimeline li").hover(function () {
            Obj = $(this).children(".shuoshuo_author_img");
            Obj = Obj.children("img");
            oldClass = Obj.attr("class");
            var newClass = oldClass + " zhuan";
            Obj.attr("class", newClass);
        }, function () {
            Obj.attr("class", oldClass);
        });
    });
</script>
<?php
get_footer();

新建页面,选择模板

最后刷新前后端,后台在自定义页面选择模板【说说微语】即可。

效果预览:https://www.lifd.site/something-to-say/

除非注明,否则均为李锋镝的博客原创文章,转载必须以链接形式标明本文链接

本文链接:https://www.lifengdi.com/article/4278