fix: collapse empty homepage sidebar
This commit is contained in:
@@ -54,6 +54,29 @@ function aksrt_resolve_sidebar_id(): string {
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_has_current_sidebar_widgets')):
|
||||
/**
|
||||
* Whether the current page has widgets for its site-sidebar column.
|
||||
*
|
||||
* The global top/bottom zones are rendered alongside the page-specific
|
||||
* sidebar, so any of these zones makes the column meaningful.
|
||||
*/
|
||||
function aksrt_has_current_sidebar_widgets(): bool {
|
||||
$sidebar_id = function_exists('aksrt_resolve_sidebar_id')
|
||||
? aksrt_resolve_sidebar_id()
|
||||
: 'home_sidebar';
|
||||
$sidebar_ids = array_unique(['all_sidebar_top', $sidebar_id, 'all_sidebar_bottom']);
|
||||
|
||||
foreach ($sidebar_ids as $sidebar_id) {
|
||||
if (is_active_sidebar($sidebar_id)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
endif;
|
||||
|
||||
if (!function_exists('aksrt_get_post_show_layout')):
|
||||
/**
|
||||
* Zibll-compatible post/page layout override.
|
||||
@@ -218,9 +241,7 @@ function aksrt_get_site_layout(): int {
|
||||
if (is_single()) {
|
||||
$post_id = (int) get_queried_object_id();
|
||||
$layout = aksrt_get_post_show_layout($post_id);
|
||||
$has_article_widgets = is_active_sidebar('all_sidebar_top')
|
||||
|| is_active_sidebar('sidebar-article')
|
||||
|| is_active_sidebar('all_sidebar_bottom');
|
||||
$has_article_widgets = aksrt_has_current_sidebar_widgets();
|
||||
// Keep the sidebar in the document whenever it is configured. CSS handles
|
||||
// narrow viewports; wp_is_mobile() is User-Agent based and can otherwise
|
||||
// suppress widgets on a desktop-sized page.
|
||||
@@ -243,6 +264,10 @@ function aksrt_get_site_layout(): int {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!aksrt_has_current_sidebar_widgets()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
$position = 'right';
|
||||
if (is_singular()) {
|
||||
$meta = aksrt_get_post_show_layout(get_queried_object_id());
|
||||
|
||||
@@ -146,14 +146,21 @@ if (!function_exists('aksrt_homepage_has_sidebar')) {
|
||||
* Whether the fixed homepage should render an aside column.
|
||||
*/
|
||||
function aksrt_homepage_has_sidebar(): bool {
|
||||
$has_widgets = function_exists('aksrt_has_current_sidebar_widgets')
|
||||
? aksrt_has_current_sidebar_widgets()
|
||||
: aksrt_homepage_has_active_sidebars([
|
||||
'all_sidebar_top',
|
||||
'home_sidebar',
|
||||
'all_sidebar_bottom',
|
||||
]);
|
||||
if (!$has_widgets) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (function_exists('aksrt_is_show_sidebar')) {
|
||||
return aksrt_is_show_sidebar();
|
||||
}
|
||||
return aksrt_homepage_has_active_sidebars([
|
||||
'all_sidebar_top',
|
||||
'home_sidebar',
|
||||
'all_sidebar_bottom',
|
||||
]);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user