is_active_sidebar()判断当前的边栏是否激活

目录

描述

This Conditional Tag checks if a given sidebar is active (in use). This is a boolean function, meaning it returns either TRUE or FALSE.

Any sidebar that contains widgets will return TRUE, whereas any sidebar that does not contain any widgets will return FALSE.

is_active_sidebar() 描述

用法

 <?php is_active_sidebar$index ); ?> 

is_active_sidebar() 用法

参数

$index

(mixed) (必填) Sidebar name or id.

默认值: None

is_active_sidebar() 参数

返回值

(boolean) 

True if the sidebar is in use, otherwise the function returns false

is_active_sidebar() 返回值

示例

Display different output depending on whether the sidebar is active or not.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

<?php if ( is_active_sidebar( 'left-sidebar' ) ) { ?>
	<ul id="sidebar">
		<?php dynamic_sidebar( 'left-sidebar' ); ?>
	</ul>
<?php } ?>

in the "Twenty Ten" theme (3.0+)

is_active_sidebar() 示例

历史

添加于 版本: 2.8.0

is_active_sidebar() 历史

源文件

is_active_sidebar() 函数的代码位于 wp-includes/widgets.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Whether a sidebar is in use.
 *
 * @since 2.8.0
 *
 * @param string|int $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();
	$is_active_sidebar = ! empty( $sidebars_widgets[$index] );

	/**
	 * Filter whether a dynamic sidebar is considered "active".
	 *
	 * @since 3.9.0
	 *
	 * @param bool       $is_active_sidebar Whether or not the sidebar should be considered "active".
	 *                                      In other words, whether the sidebar contains any widgets.
	 * @param int|string $index             Index, name, or ID of the dynamic sidebar.
	 */
	return apply_filters( 'is_active_sidebar', $is_active_sidebar, $index );
}

/* Internal Functions */

is_active_sidebar() 源文件

相关