我正在上Udemy课程,学习如何制作Wordpress插件和主题。我正在观看的视频让我通过searchform用一个自定义的搜索小部件覆盖默认的搜索小部件。php。根据我收集的信息,只要我遵循以下步骤,该文件应自动加载主题的其余部分:
/主题目录/功能。php
/* Some other code */
include ( get_theme_file_path(\'/includes/widgets.php\') );
add_action("widgets_init", \'ju_widgets\');
/theme\\u dir/includes/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\' => \'<div id="%1$s" class="widget clearfix %2$s">\',
\'after_widget\' => \'</div>\',
\'before_title\' => \'<h4>\',
\'after_title\' => \'</h4>\',
]);
}
/theme\\u目录/侧栏。php
<div class="sidebar nobottommargin col_last">
<div class="sidebar-widgets-wrap">
<?php
if (is_active_sidebar(\'ju_sidebar\')) {
dynamic_sidebar(\'ju_sidebar\');
}
?>
</div>
</div>
/theme\\u目录/searchform。php
<?php $unique_id = esc_attr( uniqid( \'search-form-\' ) ); ?>
<form role="search" method="get" class="search-form"
action="<?php echo esc_url( home_url( \'/\' ) ); ?>">
<div class="input-group">
<input type="search" id="<?php echo $unique_id; ?>"
class="form-control" name="s"
value="<?php the_search_query(); ?>"
placeholder="<?php _e( \'Search\', \'udemy\' ); ?>"/>
<span class="input-group-btn">
<button type="submit" class="btn btn-danger"><i class="icon-search"></i></button>
</span>
</div>
</form>
/theme\\u目录/索引。php
<!-- some theme html -->
<?php get_sidebar(); ?>
<!-- other theme html -->
无论我在searchform中做了什么更改。php文件,它不会替换默认的搜索小部件。