【发布时间】:2019-07-11 22:58:34
【问题描述】:
所以,我正在使用 Woocommerce 插件从头开始为 Wordpress 制作自己的主题。我似乎可以找到如何将侧边栏小部件添加到我的商店页面...在小部件菜单中没有它的区域,我似乎无法找到如何创建和编辑它...
谁能帮助我了解如何创建它以及我需要在我的子主题中创建哪些文件/代码?
【问题讨论】:
标签: php wordpress woocommerce sidebar woocommerce-theming
所以,我正在使用 Woocommerce 插件从头开始为 Wordpress 制作自己的主题。我似乎可以找到如何将侧边栏小部件添加到我的商店页面...在小部件菜单中没有它的区域,我似乎无法找到如何创建和编辑它...
谁能帮助我了解如何创建它以及我需要在我的子主题中创建哪些文件/代码?
【问题讨论】:
标签: php wordpress woocommerce sidebar woocommerce-theming
你需要使用这个函数在你的functions.php中创建一个小部件区域:
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name' => 'Sidebar',
'before_widget' => '<div class = "widget">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
)
);
并在您的主题中显示:
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Sidebar") ) : ?>
【讨论】:
<?php get_header(); ?><div id="main" class="row"> <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Shop Sidebar") ) : ?><div class="col-lg-3"></div><?php endif;?> <div id="content" class="col-lg-12 col-sm-6 col-md-6 col-xs-12"><?php woocommerce_content(); ?></div></div><?php get_footer(); ?> 它显示在商店中页面,但在所有其他内容之前......并且仅在商店页面中。这种方式显示在产品页面中...
例如在 header.php 上试试这个,你可以在你想要的地方添加侧边栏
if ( is_active_sidebar( 'Sidebar' ) ) {
dynamic_sidebar( 'Sidebar' );
}
【讨论】: