首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wordpress检查widget位置是否有widget

Wordpress检查widget位置是否有widget
EN

Stack Overflow用户
提问于 2012-12-30 18:50:17
回答 1查看 1.1K关注 0票数 0

我已经在wordpress主题中创建了小工具位置:

代码语言:javascript
复制
    <div class="row">
        <?php if ( dynamic_sidebar('Top')) ?>
    </div>

如果在这个位置没有任何活动的小工具,那么我想隐藏整个代码。

有没有像joomla那样的wordpress代码?

<?php if($this->countModules('Top')): ?>

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-12-30 19:04:00

is_active_sidebar应该做这项工作,至少WP源代码看起来好像函数会检查,如果侧边栏是空的:

代码语言:javascript
复制
/**
* Whether a sidebar is in use.
*
* @since 2.8
*
* @param mixed $index Sidebar name, id or number to check.
* @return bool true if the sidebar is in use, false otherwise.
*/
function is_active_sidebar( $index ) {
   $index = ( is_int($index) ) ? "sidebar-$index" : sanitize_title($index);
   $sidebars_widgets = wp_get_sidebars_widgets();
   if ( !empty($sidebars_widgets[$index]) )
           return true;
   return false;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14090081

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档