is_active_sidebar() WP 2.8
Проверяет используется ли указанная панель виджетов (область для виджетов, сайдбар). Сработает если в области для виджетов есть хоть один виджет. Условный тег.
Проверяет активен ли сайдбар (добавлены ли в указанную область какие-либо виджеты).
Чтобы проверить поддерживает ли тема функцию виджетов и есть ли хоть одна активная панель с виджетами, используйте функцию is_dynamic_sidebar().
Если нужно проверить активен ли конкретный виджет, а не панель виджетов, используйте функцию is_active_widget()
Хуки из функции
Возвращает
true/false. Возвращает true, если хоть один виджет добавлен. Вернет false, если сайдбар не имеет ни одного виджета.
Использование
if( is_active_sidebar( $index ) ){ // код }
- $index(строка/число) (обязательный)
- Название панели виджетов, области виджетов (сайдбара), ID панели или порядковый номер. Если передано число, то функция ищет область с идентификатором
sidebar-$index
.
Примеры
#1 Определим активен ли виджет
Выведем на экран различный текст, в зависимости от того, активен виджет или нет:
if ( is_active_sidebar(1) ) { echo "Сайдбар 1 имеет виджеты."; } else { echo "Сайдбар 1 пустой."; };
#2 Только не пустая панель виджетов
Выведем панель виджетов 'left-sidebar' в шаблоне, только если для нее установлен хотя бы один виджет:
<?php if ( is_active_sidebar( 'left-sidebar' ) ){ ?> <ul id="sidebar"> <?php dynamic_sidebar( 'left-sidebar' ); ?> </ul> <?php } ?>
Список изменений
С версии 2.8.0 | Введена. |
Код is_active_sidebar() is active sidebar WP 5.6
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 );
}Cвязанные функции
Из метки: sidebar (widget Виджет)
- dynamic_sidebar()
- is_active_widget()
- is_dynamic_sidebar()
- is_registered_sidebar()
- register_sidebar()
- register_sidebars()
Еще из метки: Условные теги (все)
- cat_is_ancestor_of()
- comments_open()
- email_exists()
- has_block()
- has_category()
- has_custom_header()
- has_excerpt()
- has_nav_menu()
- has_post_thumbnail()
- has_shortcode()
- has_tag()
- has_term()
- have_comments()
- have_posts()
- in_category()
- in_the_loop()
- is_404()
- is_admin()
- is_admin_bar_showing()
- is_archive()
- is_attachment()
- is_author()
- is_blog_admin()
- is_blog_installed()
- is_category()
- is_child_theme()
- is_comment_feed()
- is_customize_preview()
- is_date()
- is_day()
- is_embed()
- is_feed()
- is_front_page()
- is_header_video_active()
- is_home()
- is_local_attachment()
- is_main_query()
- is_month()
- is_multi_author()
- is_multisite()
- is_nav_menu()
- is_network_admin()
- is_new_day()
- is_page()
- is_page_template()
- is_paged()
- is_plugin_active()
- is_post_type_archive()
- is_post_type_hierarchical()
- is_preview()
- is_robots()
- is_search()
- is_single()
- is_singular()
- is_ssl()
- is_sticky()
- is_tag()
- is_tax()
- is_taxonomy_hierarchical()
- is_textdomain_loaded()
- is_time()
- is_trackback()
- is_user_admin()
- is_user_logged_in()
- is_year()
- pings_open()
- post_exists()
- post_password_required()
- shortcode_exists()
- taxonomy_exists()
- term_exists()
- term_is_ancestor_of()
- wp_attachment_is()
- wp_attachment_is_image()
- wp_doing_ajax()
- wp_doing_cron()
- wp_is_mobile()
- wp_is_post_autosave()
- wp_is_post_revision()
- wp_script_is()
Еще из тегов шаблона: Основные
- bloginfo()
- calendar_week_mod()
- get_archives_link()
- get_bloginfo()
- get_calendar()
- get_current_blog_id()
- get_footer()
- get_header()
- get_search_form()
- get_sidebar()