我已经在wordpress主题中创建了小工具位置:
<div class="row">
<?php if ( dynamic_sidebar('Top')) ?>
</div>如果在这个位置没有任何活动的小工具,那么我想隐藏整个代码。
有没有像joomla那样的wordpress代码?
<?php if($this->countModules('Top')): ?>
发布于 2012-12-30 19:04:00
is_active_sidebar应该做这项工作,至少WP源代码看起来好像函数会检查,如果侧边栏是空的:
/**
* 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;
}https://stackoverflow.com/questions/14090081
复制相似问题