我正在选修Udemy课程,学习如何制作Wordpress插件和主题。我正在播放的视频是让我通过searchform.php使用一个定制的搜索小部件覆盖默认搜索小部件。根据我收集的内容,只要我遵循以下步骤,这个文件就会自动加载到主题的其余部分:
/theme_dir/functions.php s.php
/* Some other code */
include ( get_theme_file_path('/includes/widgets.php') );
add_action("widgets_init", 'ju_widgets');/theme_dir/include/widgets.php
function ju_widgets() {
register_sidebar([
'name' => __('My First Theme Sidebar', 'udemy'),
'id' => 'ju_sidebar',
'description' => __('Sidebar for the theme Udemy', 'udemy'),
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '',
]);
}/theme_dir/sidebar.php
/theme_dir/searchform.php
/theme_dir/index.php
无论我在searchform.php文件中更改了什么,它都不会替换默认的搜索小部件。
发布于 2021-11-08 23:25:37
这种使用小部件的方式已经过时,我应该使用Gutenberg块。故事的寓意是,在从乌德米那里购买课程时要小心,它们可能是无用的。
发布于 2022-04-21 23:26:52
发布这个问题的人可能正在上这门课,因为我认得代码:完成WordPress开发人员课程-插件和主题。
我也参加了这门课程,下面是我如何在我的Gutenberg WordPress站点中使用searchform.php模板文件:
最后,以上的Udemy课程确实包括关于古腾堡的部分(Gutenberg先决条件、Gutenberg开发等等)。所以我认为这门课还是值得一试的。然后进入古腾堡课程的章节,您可以禁用或卸载禁用Gutenberg插件和Gutenberg特性将被恢复。
https://wordpress.stackexchange.com/questions/397873
复制相似问题