我正在尝试在Wordpress中输出一个侧边栏,具体取决于它是否具有小部件(处于活动状态),并相应地在我的 Shop 页面上显示它们。
我对 PHP 很不熟悉,到目前为止,我已经编写了以下脚本来尝试使其工作,但它似乎没有发生。
商店.php:
<?php
/**
* The template for displaying the Shop page.
*/
get_header(); ?>
<div id="primary" class="site-content">
<div id="content" role="main">
<?php shop_content(); ?>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar('shop'); ?>
<?php get_footer(); ?>
侧边栏-shop.php:
<?php
/**
* The sidebar containing the Shop page widget areas.
*
* If no active widgets are in the sidebars (Left, Right and theShop),
* the sidebars should be hidden completely.
*/
?>
<?php
// If the left, shop and right sidebars are inactive
if ( ! is_active_sidebar( 'right-sidebar' ) && ! is_active_sidebar( 'shop-sidebar' ) ) {
return;
}
// If there are active widgets in the Shop Sidebar
if ( is_active_sidebar( 'shop-sidebar' ) ) { ?>
<div id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'shop-sidebar' ); ?>
</div><!-- #secondary -->
<?php
}
// If there are active widgets in the Right Sidebar
elseif ( is_active_sidebar( 'right-sidebar' ) ) { ?>
<div id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'right-sidebar' ); ?>
</div><!-- #secondary -->
<?php
}
?>
边栏.php:
<?php
/**
* The sidebar containing the main widget area.
*
* If no active widgets in sidebar, let's hide it completely.
*
*/
?>
<?php if ( is_active_sidebar( 'right-sidebar' ) ) : ?>
<div id="secondary" class="widget-area" role="complementary">
<?php dynamic_sidebar( 'right-sidebar' ); ?>
</div><!-- #secondary -->
<?php endif; ?>
我将如何修改上面的脚本以输出以下内容:
- 如果右侧边栏(right-sidebar)有小部件,显示右侧边栏
- 如果 Shop Sidebar (shop-sidebar) 有小部件,则显示 Shop Sidebar
- 如果右侧边栏和商店边栏都有小部件,则显示商店边栏
- 如果右侧边栏或商店边栏都没有任何小部件,则不要显示任何内容
谢谢你。