aksrt_homepage_get_post_types(), 'post_status' => 'publish', 'posts_per_page' => max(1, (int) get_option('posts_per_page')), 'paged' => aksrt_homepage_get_current_page(), 'ignore_sticky_posts' => false, 'orderby' => 'date', 'order' => 'DESC', 'no_found_rows' => false, ]; $exclude_ids = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::home_exclude_post_ids() : []; if (!empty($exclude_ids)) { $query_args['post__not_in'] = $exclude_ids; } $exclude_cat_ids = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::home_exclude_category_ids() : []; if (!empty($exclude_cat_ids)) { $query_args['category__not_in'] = $exclude_cat_ids; } $query = new WP_Query(aksrt_homepage_apply_sort_args($query_args)); return $query; } } if (!function_exists('aksrt_homepage_get_tab_query')) { /** * Build a category-tab query. */ function aksrt_homepage_get_tab_query(int $term_id, string $orderby = 'date'): WP_Query { static $queries = []; $cache_key = $term_id . '_' . $orderby; if (isset($queries[$cache_key]) && $queries[$cache_key] instanceof WP_Query) { return $queries[$cache_key]; } $term = get_term($term_id); $taxonomy = ($term && !is_wp_error($term)) ? (string) $term->taxonomy : 'category'; if ($taxonomy !== 'category') { $taxonomy = 'category'; } $query_args = [ 'post_type' => aksrt_homepage_get_post_types(), 'post_status' => 'publish', 'posts_per_page' => class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::homepage_tab_posts_per_page() : 6, 'ignore_sticky_posts' => true, 'orderby' => 'date', 'order' => 'DESC', 'no_found_rows' => true, 'tax_query' => [ [ 'taxonomy' => $taxonomy, 'field' => 'term_id', 'terms' => [$term_id], ], ], ]; $exclude_ids = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::home_exclude_post_ids() : []; if (!empty($exclude_ids)) { $query_args['post__not_in'] = $exclude_ids; } $queries[$cache_key] = new WP_Query( aksrt_homepage_apply_named_sort_args($query_args, $orderby) ); return $queries[$cache_key]; } } if (!function_exists('aksrt_homepage_has_active_sidebars')) { /** * Check whether any sidebar in the given stack is active. * * @param string[] $sidebar_ids */ function aksrt_homepage_has_active_sidebars(array $sidebar_ids): bool { foreach ($sidebar_ids as $sidebar_id) { if (is_active_sidebar($sidebar_id)) { return true; } } return false; } } if (!function_exists('aksrt_homepage_render_widget_zone')) { /** * Render a stacked widget zone. * * @param string[] $sidebar_ids * @param string $wrapper_class */ function aksrt_homepage_render_widget_zone(array $sidebar_ids, string $wrapper_class = ''): void { if (!aksrt_homepage_has_active_sidebars($sidebar_ids)) { wp_reset_postdata(); return; } echo '
'; foreach ($sidebar_ids as $sidebar_id) { if (is_active_sidebar($sidebar_id)) { dynamic_sidebar($sidebar_id); } } echo '
'; } } 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 true; } } if (!function_exists('aksrt_homepage_render_sidebar')) { /** * Render the homepage aside column. */ function aksrt_homepage_render_sidebar(): void { if (!aksrt_homepage_has_sidebar()) { return; } echo ''; } } if (!function_exists('aksrt_homepage_get_latest_panel_contract')) { /** * Public-safe latest stream contract shared by homepage pagination/AJAX. * * @return array{query_context:string,query_vars:string,render_config:string,render_config_array:array} */ function aksrt_homepage_get_latest_panel_contract(): array { $query = aksrt_homepage_get_latest_query(); $query_vars = $query instanceof WP_Query ? $query->query_vars : []; if (!is_array($query_vars)) { $query_vars = []; } unset($query_vars['paged'], $query_vars['page']); $render_config = aksrt_resolve_post_list_render_config(['context' => 'home']); $render_config['skip_wrapper'] = true; return [ 'query_context' => 'homepage_latest', 'query_vars' => (string) wp_json_encode($query_vars), 'render_config' => (string) wp_json_encode($render_config), 'render_config_array' => $render_config, ]; } } if (!function_exists('aksrt_homepage_render_pagination')) { /** * Render pagination for the fixed homepage latest stream. */ function aksrt_homepage_render_pagination(WP_Query $query): void { $max_pages = (int) $query->max_num_pages; if ($max_pages < 2) { return; } $query_page = (int) $query->get('paged'); $current_page = min(max(1, $query_page > 0 ? $query_page : aksrt_homepage_get_current_page()), $max_pages); $pagination_mode = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_post_pagination_mode() : 'numbered'; if ($pagination_mode === 'numbered') { $base_url = (string) get_query_var('aksrt_homepage_pagination_base_url'); $base_args = [ 'format' => '', 'current' => $current_page, 'total' => $max_pages, 'mid_size' => 2, 'prev_text' => '', 'next_text' => '', 'type' => 'array', ]; if ($base_url !== '') { $base_args['base'] = add_query_arg( 'paged', '%#%', remove_query_arg(['paged', 'page'], $base_url) ); } else { $base_args['base'] = str_replace(999999999, '%#%', esc_url(get_pagenum_link(999999999))); } $links = paginate_links($base_args); if (!$links || !is_array($links)) { return; } ?>
]+src=["\x27]([^"\x27]+)["\x27]/i', $content, $html_matches) && !empty($html_matches[1])) { foreach ($html_matches[1] as $raw_url) { $images[] = esc_url_raw((string) $raw_url); } } if (preg_match_all('/"url"\s*:\s*"([^"]+)"/i', $content, $block_matches) && !empty($block_matches[1])) { foreach ($block_matches[1] as $raw_url) { $images[] = esc_url_raw((string) $raw_url); } } } $images = array_values(array_unique(array_filter($images, static function ($url) { return is_string($url) && $url !== ''; }))); set_transient($transient_key, $images, DAY_IN_SECONDS); $request_cache[$post_id] = $images; return array_slice($images, 0, $limit); } } if (!function_exists('aksrt_homepage_render_posts_grid')) { /** * Render a list block for the fixed homepage. */ function aksrt_homepage_render_posts_grid(?WP_Query $query = null, bool $with_pagination = false): void { $query = $query instanceof WP_Query ? $query : aksrt_homepage_get_latest_query(); $config = aksrt_resolve_post_list_render_config(['context' => 'home']); $config['skip_wrapper'] = true; // Panel already provides posts-row.ajaxpager; avoid nested wrapper. aksrt_render_post_list($config, $query, true); if ($with_pagination) { aksrt_homepage_render_pagination($query); } } } if (!function_exists('aksrt_homepage_render_section')) { /** * Render a first-class homepage section (hero / banner). * * These are fixed homepage sections, not a freeform module canvas bridge. */ function aksrt_homepage_render_section(string $type): void { $type = sanitize_key($type); if (!in_array($type, ['hero', 'banner'], true)) { return; } // Fixed homepage owns these sections directly. // Keep the existing hero/banner templates as section implementations, // but do not re-wrap them in a freeform module bridge. get_template_part('templates/parts/home-modules/module', $type); } }