is_active_sidebar() - WordPress 函数参考中文文档

返回介绍

is_active_sidebar()

发布于 2017-09-11 字数2423 浏览 1076 评论 0

is_active_sidebar( string|int $index )

Whether a sidebar is in use.


描述


参数

$index

(string|int)
(Required)
Sidebar name, id or number to check.


返回值

(bool) true if the sidebar is in use, false otherwise.


源代码

File: wp-includes/widgets.php

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] );

	/**
	 * Filters 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 );
}

更新日志

Version 描述
2.8.0 Introduced.

相关函数

Uses

  • wp-includes/formatting.php:
    sanitize_title()
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/widgets.php:
    wp_get_sidebars_widgets()
  • wp-includes/widgets.php:
    is_active_sidebar

User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: 1You must log in to vote on the helpfulness of this note

    Contributed by Codex

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

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

上一篇:is_404()

下一篇:is_active_widget()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!