WordPress 插件为主题提供页面模板
像素鱼丸
2024-09-25
655
0
/* 加载页面模板 */
add_filter( 'page_template', 'marker_page_template' );
function marker_page_template( $page_template ) {
    if ( get_page_template_slug() == 'markerv' ) {
        $page_template = MARKER_DIR . '/templates/markerv.php';
    }
    if ( get_page_template_slug() == 'test' ) {
        $page_template = MARKER_DIR . '/templates/test.php';
    }
    return $page_template;
}

/* 添加到页面属性模板中 */
add_filter( 'theme_page_templates', 'marker_add_template_select', 10, 4 );
function marker_add_template_select( $post_templates, $wp_theme, $post, $post_type ) {
    $post_templates['markerv'] = __( 'markerv' );
    $post_templates['test'] = __( 'test' );
    return $post_templates;
}

模板文件:markerv.php

模板文件路径:/templates/markerv.php

显示在页面属性中的模板名称:$post_templates[‘markerv’] = __( ‘模板名称’);

收藏
打赏
Composer 教程
上一篇
Marker 插件
下一篇
像素鱼丸
149 文章
0 评论
4 喜欢
最新文章

Mirage 主题 v2.93.0 发布

更新内容: refactor 移除图片高宽比开关 refactor 移除全局的TOC生成开关 refactor 优化 header.php 中的seo模块和样式覆盖 feat 主题启用的时候,移除非当前主题注册的小工具 fix 修复分类小工具的bug feat 管理员打开后台,检查最当前设置首页布局的模块,如果缺少最新模块,就添加到隐藏模块列表中 fix 优化链接卡片样式 fix 优化热门文章样式 […]

如何使用 WordPress Setting API

使用 WordPress 的 Setting API 是在插件或主题中创建和管理设置页面的标准方式。它提供了一种结构化、安全的方式来保存和获取用户配置的选项。 ✅ 一、Setting API 简介 WordPress 的 Setting API 允许你: 创建设置页面(Settings Page) 注册设置字段(Settings Field) 验证和保存设置数据 使用表单提交来更新设置 ✅ 二、基 […]

详解 WordPress 的评论设置

好的,我们来详细梳理并总结 WordPress 中关于文章评论的两个核心控制层级:全局设置和单篇设置。理解这两者的关系(优先级)是管理网站评论的关键。 1. 全局设置 (Global Settings) —— 网站的“默认规则” 这是整个网站评论系统的总开关和默认行为准则。它决定了新发布的文章默认是什么样子的。 位置:WordPress 后台仪表盘 -> 设置 (Settings) -> […]

wp_handle_comment_submission 函数

wp_handle_comment_submission() 是 WordPress 中用于处理评论提交的核心函数之一。它通常在用户提交评论时被调用,负责验证和处理评论数据,并最终将评论插入到数据库中。 ✅ 函数作用 wp_handle_comment_submission() 的主要功能是: 验证用户提交的评论数据(如评论内容、用户名、邮箱等) 检查是否为垃圾评论(通过 Akismet 或其他过 […]
生成中...
扫描二维码
扫描二维码
用户登录