我試圖在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上面的腳本,以輸出如下:
- 如果右側欄(右側欄)具有窗口小部件,顯示右側欄
- 如果商店側欄(店鋪側欄)具有窗口小部件,顯示該商店邊欄
- 如果右邊欄和側欄店都有小部件,顯示店鋪側邊欄
- 如果既不是右邊欄或側邊欄鋪有任何部件,不顯示任何
謝謝。