我试图在Wordpress中输出一个侧边栏,具体取决于它是否具有窗口小部件(处于活动状态),并将其显示在我的Shop页面上。IF,ELSE和ELSEIF语句
我对PHP很不熟悉,到目前为止已经写了下面的脚本来尝试做这个工作,但似乎并没有发生。
shop.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
}
?>
的sidebar.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; ?>
我将如何莫dify上面的脚本,以输出如下:
- 如果右侧栏(右侧栏)具有窗口小部件,显示右侧栏
- 如果商店侧栏(店铺侧栏)具有窗口小部件,显示该商店边栏
- 如果右边栏和侧栏店都有小部件,显示店铺侧边栏
- 如果既不是右边栏或侧边栏铺有任何部件,不显示任何
谢谢。