php - 嗨,关于 wordpress require_once
问题描述
我想分离我的文件并通过不将它们放在function.php中来组织它我这样做了。
function required_theme_files() {
require_once( get_template_directory() . '/inc/customize/color.php' );
require_once( get_template_directory() . '/inc/sidebar.php' );
}
add_action( 'init', 'required_theme_files' );
但sidebar.php 根本不起作用似乎不知道问题我不是真正的程序员,更像是前端设计师。
function ounox_widget_setup() {
register_sidebar(
array(
'name' => 'Sidebar',
'id' => 'sidebar-1',
'class' => 'custom',
'description' => 'Standard Sidebar',
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h6 class="widget-title">',
'after_title' => '</h6>',
)
);
}
add_action( 'widgets_init','ounox_widget_setup' );
解决方案
尝试 Debug 并查看您遇到了哪些 PHP 错误,例如sidebar.php
未加载或未找到。见https://codex.wordpress.org/WP_DEBUG
添加
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', false);
在 wp-config.php 和 debug.log 文件将在 wp-content 中。
将“显示”行更改为 true
define( 'WP_DEBUG_DISPLAY', true);
将它们转储到浏览器并记录它们。
<?php
1)顶部有开口sidebar.php
吗?
2)或者,您的问题可能是使用get_template_directory
. 这将返回绝对服务器路径(例如:/home/user/public_html/wp-content/themes/my_theme),而不是 URI。
在使用子主题的情况下,将返回父主题目录的绝对路径。用于get_stylesheet_directory()
获取子主题目录的绝对路径。请参阅get_stylesheet_directory_uri() | WordPress 开发人员资源
推荐阅读
- python - 在python中存储正则表达式字符串的干净方法
- javascript - 如何计算待办事项列表中已检查元素的数量和总元素的数量
- node.js - audio/webm Google 与 Cloud Speech-to-Text
- angular - 角度异常:“Access-Control-Allow-Origin”缺少 VIES
- docker - Hyperledger Fabric byfn 实例化失败 - 链码存在
- java - hamcrest:使用 hamcrest 在逻辑上比较两个集合 ob 自定义类
- html - 如何将悬停效果添加到 textarea 占位符?
- sql - SQL - 使用当前和前几年的值创建视图
- java - 无法使用 gradle 和 jdk 11 构建 jar
- json - JQ:用另一个文件中的相应值替换键