[7B2主题优化]在文章底部加个模块(自动获取文章链接+标题+一些说明)

[7B2主题优化]在文章底部加个模块(自动获取文章链接+标题+一些说明)-源码资源网
[7B2主题优化]在文章底部加个模块(自动获取文章链接+标题+一些说明)
此内容为付费阅读,请付费后查看
9.9
限时特惠
38
立即购买
您当前未登录!建议登陆后购买,可保存购买订单
付费阅读
已售 65

模块样式,效果如图,这个有利于提示用户文章的失效,在底部加个链接也有利于SEO蜘蛛爬行。

[7B2主题优化]在文章底部加个模块(自动获取文章链接+标题+一些说明)下面我来教大家怎么加个模块吧!

第一步:在主题的functions.php文件里面加入以下代码。

[登录可见]隐藏内容 – 管理员可见
// 创建短代码显示当前链接、文章标题、发布日期(精确到秒)
function custom_article_info_with_styled_date() {
    global $post;
    $post_title = get_the_title(); // 获取文章标题
    $post_date = get_the_date(\'Y年m月d日 H:i\'); // 获取文章发布日期,精确到秒
    $current_url = get_permalink(); // 获取当前文章链接
    return \'
    <div class=\"article-info\">
        <p>当前链接:<a href=\"\' . $current_url . \'\" target=\"_blank\">\' . $current_url . \'</a></p>
        <p>文章标题:<strong>\' . $post_title . \'</strong></p>
        <p>文章版权:技术巢 (https://js.vmccc.com) 所发布的内容,部分为原创文章,转载请注明来源,网络转载文章如有侵权请联系我们!</p>
 <p>本文最后更新发布于:<span class=\"styled-date\">\' . $post_date . \'</span>,某些文章具有时效性,若有错误或已失效,请在下方留言。</p>
    </div>
    \';
}
add_shortcode(\'article_info\', \'custom_article_info_with_styled_date\');

第二步:在目录b2/Assets/fontend/style.css文件里面加入以下代码:

[登录可见]隐藏内容 – 管理员可见
/*文章页面自动获取标题,链接,发布时间*/
.article-info {
    background-color: #f9f9f9;
    border: 1px solid #fff;
    padding: 8px;
    border-radius: 5px;
    margin-top: 20px;
    font-size: 14px;
    line-height: 1.6;
}
.article-info p {
    margin: 8px 0;
}
.article-info a {
    color: #007bff;
    text-decoration: none;
}
.article-info a:hover {
    text-decoration: underline;
}
/* 为日期部分添加浅蓝色背景 */
.article-info .styled-date {
    background-color: #e6f7ff; /* 浅蓝色背景 */
    padding: 2px 5px;         /* 内边距 */
    border-radius: 3px;       /* 圆角 */
    color: #333;             /* 文字颜色 */
    font-weight: bold;       /* 加粗字体 */
}
/*文章页面自动获取标题,链接,发布时间 结束*/

第三步:打开目录/b2/Modules/Templates/Single.php这个文件,搜索:public function post_ds在这个代码下面添加:

echo do_shortcode(\'[article_info]\');

这个代码是在文章页面载入模块信息。代码添加位置,如图所示:

[7B2主题优化]在文章底部加个模块(自动获取文章链接+标题+一些说明)
然后就完成了,CSS文件有改动记得清理浏览器缓存刷新网站才能看到效果~

重要提示

如有解压密码: 看下载页、看下载页、看下载页。
源码工具资源类具有可复制性: 建议具有一定思考和动手能力的用户购买。
请谨慎考虑: 小白用户和缺乏思考动手能力者不建议赞助。
虚拟商品购买须知: 虚拟类商品,一经购买打赏赞助,不支持退款。请谅解,谢谢合作!

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容