fix 更多栏目

This commit is contained in:
kate522 committed 2026-09-05 17:32:18 +08:00
1 parent 5b89fc200b
commit 05a6b6fc54
28 files changed
+440 -2295

No files matched your search

+127 -107
View File
@@ -46,7 +46,7 @@ if (!function_exists('aksrt_homepage_get_post_types')) {
}
if (!function_exists('aksrt_homepage_get_tab_terms')) {
if (!function_exists('aksrt_homepage_get_tab_configs')) {
/**
* Homepage category tabs with full config.
*
@@ -88,52 +88,12 @@ if (!function_exists('aksrt_homepage_get_tab_terms')) {
'term' => $term,
'term_id' => (int) $tab['term_id'],
'title' => $tab['title'] !== '' ? $tab['title'] : $term->name,
'orderby' => $tab['orderby'] ?: 'modified',
'orderby' => $tab['orderby'] ?: '',
];
}
return $configs;
}
/**
* Homepage category tabs — returns WP_Term objects for backward compat.
*
* @param int $limit Unused, reads from settings.
* @return WP_Term[]
*/
function aksrt_homepage_get_tab_terms(int $limit = 4): array {
$configs = aksrt_homepage_get_tab_configs();
return array_column($configs, 'term');
}
}
if (!function_exists('aksrt_homepage_get_tab_posts_per_page')) {
/**
* Per-tab homepage post count.
*/
function aksrt_homepage_get_tab_posts_per_page(): int {
if (class_exists('\AKSRT\Settings\Settings')) {
$count = \AKSRT\Settings\Settings::homepage_tab_posts_per_page();
if ($count > 0) {
return max(1, min(20, $count));
}
}
return 6;
}
}
if (!function_exists('aksrt_homepage_sticky_tabs_enabled')) {
/**
* Whether homepage tabs should stick below the primary nav.
*/
function aksrt_homepage_sticky_tabs_enabled(): bool {
if (class_exists('\AKSRT\Settings\Settings')) {
return \AKSRT\Settings\Settings::homepage_sticky_tabs_enabled();
}
return true;
}
}
if (!function_exists('aksrt_homepage_get_sort_mode')) {
@@ -156,32 +116,23 @@ if (!function_exists('aksrt_homepage_get_sort_mode')) {
}
}
if (!function_exists('aksrt_homepage_get_sort_items')) {
if (!function_exists('aksrt_homepage_get_request_sort')) {
/**
* Configured sort bar items for the main stream.
* Main-stream sort requested by URL (?orderby=), legacy zib_sift_posts_per_orde.
*
* @return array<string,string>
* 排序菜单(.ajax-option)点击后原位刷新的响应页靠它同序。
*/
function aksrt_homepage_get_sort_items(): array {
$all_labels = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::homepage_sort_labels()
: [
'modified' => '更新', 'date' => '发布', 'views' => '浏览',
'like' => '点赞', 'comment_count' => '评论', 'favorite' => '收藏', 'rand' => '随机',
];
$enabled_keys = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::home_list_sort_options()
: array_keys($all_labels);
$items = [];
foreach ($enabled_keys as $key) {
if (isset($all_labels[$key])) {
$items[$key] = $all_labels[$key];
}
function aksrt_homepage_get_request_sort(): string {
$get_sort = isset($_GET['orderby']) ? sanitize_key(wp_unslash((string) $_GET['orderby'])) : '';
if ($get_sort === '') {
return '';
}
return !empty($items) ? $items : ['modified' => '更新', 'date' => '发布'];
$allowed = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::homepage_allowed_sorts()
: ['modified', 'date', 'views', 'like', 'comment_count', 'favorite', 'rand'];
return in_array($get_sort, $allowed, true) ? $get_sort : '';
}
}
@@ -269,55 +220,124 @@ if (!function_exists('aksrt_homepage_apply_named_sort_args')) {
}
}
if (!function_exists('aksrt_homepage_render_sortbar')) {
if (!function_exists('aksrt_homepage_render_ajax_option_menu')) {
/**
* Render the main-stream sort bar.
* 首页排序菜单,1:1 zib_ajax_option_menu('home')。
*
* 输出 .ajax-option.ajax-replace[win-ajax-replace="filter"],点击 .ajax-next
* 排序链接由 runtime post_ajax 原位替换 #index-tab-main 内的列表。
*/
function aksrt_homepage_render_sortbar(): void {
if (class_exists('\AKSRT\Settings\Settings') && !\AKSRT\Settings\Settings::home_list_sort_enabled()) {
function aksrt_homepage_render_ajax_option_menu(): void {
if (!empty($_GET['nofilter'])) {
return;
}
$current = aksrt_homepage_get_sort_mode();
$is_dropdown = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::home_list_sort_dropdown()
: false;
$sort_items = aksrt_homepage_get_sort_items();
$all_labels = class_exists('\AKSRT\Settings\Settings')
if (!class_exists('\AKSRT\Settings\Settings') || !\AKSRT\Settings\Settings::home_list_sort_enabled()) {
return;
}
$con = aksrt_homepage_get_option_orderby_but([
'lists' => (array) \AKSRT\Settings\Settings::home_list_sort_options(),
'dropdown' => (bool) \AKSRT\Settings\Settings::home_list_sort_dropdown(),
]);
if (!$con) {
return;
}
echo '<div class="ajax-option ajax-replace" win-ajax-replace="filter">' . $con . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo '<div></div>'; // 空白内容,解决css奇数偶数行
}
}
if (!function_exists('aksrt_homepage_get_option_orderby_but')) {
/**
* 排序方式按钮组,1:1 zib_get_option_orderby_but。
*
* @param array{lists?:string[],dropdown?:bool} $option Sort option config.
*/
function aksrt_homepage_get_option_orderby_but($option = []): string {
$defaults = [
'lists' => [],
'dropdown' => false,
];
$option = wp_parse_args((array) $option, $defaults);
if (!$option['lists'] && !$option['dropdown']) {
return '';
}
$labels = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::homepage_sort_labels()
: $sort_items;
?>
<div class="aksrt-homepage__sortbar" aria-label="<?php esc_attr_e('Homepage Sort', 'aksrt'); ?>">
<?php if ($is_dropdown) : ?>
<div class="aksrt-homepage__sortbar-dropdown">
<button type="button" class="aksrt-homepage__sortbar-current" data-sort-dropdown-trigger>
<?php echo esc_html($all_labels[$current] ?? $current); ?>
<i class="fa fas fa-caret-down" aria-hidden="true"></i>
</button>
<div class="aksrt-homepage__sortbar-dropdown-menu" hidden>
<?php foreach ($sort_items as $sort_key => $label) : ?>
<button type="button"
class="aksrt-homepage__sortbar-dropdown-item<?php echo $sort_key === $current ? ' is-active' : ''; ?>"
data-sort="<?php echo esc_attr($sort_key); ?>"
>
<?php echo esc_html($label); ?>
</button>
<?php endforeach; ?>
</div>
</div>
<?php else : ?>
<div class="aksrt-homepage__sortbar-links">
<?php foreach ($sort_items as $sort_key => $label) : ?>
<button type="button"
class="aksrt-homepage__sortbar-link<?php echo $sort_key === $current ? ' is-active' : ''; ?>"
data-sort="<?php echo esc_attr($sort_key); ?>"
>
<?php echo esc_html($label); ?>
</button>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<?php
: ['modified' => '更新', 'date' => '发布', 'views' => '浏览', 'like' => '点赞', 'comment_count' => '评论', 'favorite' => '收藏', 'rand' => '随机'];
$dropdown_but = '';
$but = '';
$uri = aksrt_homepage_url_del_paged(aksrt_homepage_get_current_url());
foreach ($option['lists'] as $key) {
if (!isset($labels[$key])) {
continue;
}
$_class = 'ajax-next';
if (isset($_GET['orderby']) && sanitize_key(wp_unslash((string) $_GET['orderby'])) === $key) {
$_class .= ' focus-color';
}
$href = add_query_arg(['orderby' => $key], $uri);
$but .= '<a rel="nofollow" ajax-replace="true" class="' . esc_attr($_class) . '" href="' . esc_url($href) . '">' . esc_html($labels[$key]) . '</a>';
}
if ($option['dropdown']) {
foreach ($labels as $key => $value) {
$_class = 'ajax-next';
if (isset($_GET['orderby']) && sanitize_key(wp_unslash((string) $_GET['orderby'])) === $key) {
$_class .= ' focus-color';
}
$href = add_query_arg(['orderby' => $key], $uri);
$dropdown_but .= '<li><a rel="nofollow" ajax-replace="true" class="' . esc_attr($_class) . '" href="' . esc_url($href) . '">' . esc_html($value) . '</a></li>';
}
}
if (!$but && !$dropdown_but) {
return '';
}
$is_dropdown = ($option['dropdown'] && $dropdown_but) ? true : false;
$d_but = $is_dropdown
? '<a href="javascript:;" data-toggle="dropdown"><span name="cat">' . esc_html__('排序', 'aksrt') . '</span><i class="fa fa-fw fa-sort opacity5" aria-hidden="true"></i></a>'
: esc_html__('排序', 'aksrt');
$html = '<div class="flex ac">';
$html .= '<div class="option-dropdown splitters-this-r dropdown flex0">';
$html .= $d_but;
$html .= $is_dropdown ? '<ul class="dropdown-menu">' . $dropdown_but . '</ul>' : '';
$html .= '</div>';
$html .= '<ul class="list-inline scroll-x mini-scrollbar option-items">' . $but . '</ul>';
$html .= '</div>';
return $html;
}
}
if (!function_exists('aksrt_homepage_get_current_url')) {
/**
* 当前页面链接,1:1 zib_get_current_url。
*/
function aksrt_homepage_get_current_url(): string {
$home_url = home_url();
$host = preg_replace('/^(http|https)(:\/\/)(?)([^\/]+).*$/im', '$1$2$3', $home_url);
return $host . add_query_arg(null, false);
}
}
if (!function_exists('aksrt_homepage_url_del_paged')) {
/**
* 移除分页参数的链接,1:1 zib_url_del_paged。
*/
function aksrt_homepage_url_del_paged(string $url): string {
$url = remove_query_arg(['paged', 'page'], $url);
global $wp_rewrite;
return preg_replace('/\/' . $wp_rewrite->pagination_base . '\/\d*/', '', $url);
}
}