feat(widgets): per-tab topics/limit_day/pay_type filters

TabPosts each tab can filter topics taxonomy, date window and pay type;
REST and widget-set.js pass the extra query args.
This commit is contained in:
2026-07-21 14:36:01 +08:00
parent 0e8c9d12c7
commit 9f485cbe45
2 changed files with 28 additions and 2 deletions
+4 -1
View File
@@ -93,7 +93,10 @@ class WidgetAjax {
'orderby' => sanitize_key((string) ($request->get_param('orderby') ?? 'date')), 'orderby' => sanitize_key((string) ($request->get_param('orderby') ?? 'date')),
'count' => max(0, min(20, (int) ($request->get_param('tab_count') ?? 0))), 'count' => max(0, min(20, (int) ($request->get_param('tab_count') ?? 0))),
'enabled' => true, 'enabled' => true,
];
'topics' => sanitize_text_field((string) ($request->get_param('topics') ?? '')),
'limit_day' => max(0, (int) ($request->get_param('limit_day') ?? 0)),
'pay_type' => sanitize_key((string) ($request->get_param('pay_type') ?? '')),];
$opts = [ $opts = [
'style' => $style, 'style' => $style,
'paginate' => $paginate, 'paginate' => $paginate,
+24 -1
View File
@@ -107,6 +107,9 @@ class TabPostsWidget extends \WP_Widget {
'count' => max(1, min(30, $count)), 'count' => max(1, min(30, $count)),
'orderby' => sanitize_key((string) ($tab['orderby'] ?? 'date')), 'orderby' => sanitize_key((string) ($tab['orderby'] ?? 'date')),
'cat' => absint($tab['category_id'] ?? 0), 'cat' => absint($tab['category_id'] ?? 0),
'topics' => sanitize_text_field((string) ($tab['topics'] ?? '')),
'limit_day' => max(0, (int) ($tab['limit_day'] ?? 0)),
'pay_type' => sanitize_key((string) ($tab['pay_type'] ?? '')),
'style' => $style, 'style' => $style,
'show_thumb' => !isset($opts['show_thumb']) ? 1 : (int) $opts['show_thumb'], 'show_thumb' => !isset($opts['show_thumb']) ? 1 : (int) $opts['show_thumb'],
'show_meta' => !isset($opts['show_meta']) ? 1 : (int) $opts['show_meta'], 'show_meta' => !isset($opts['show_meta']) ? 1 : (int) $opts['show_meta'],
@@ -213,6 +216,9 @@ class TabPostsWidget extends \WP_Widget {
data-orderby="<?php echo esc_attr($tab['orderby']); ?>" data-orderby="<?php echo esc_attr($tab['orderby']); ?>"
data-cat="<?php echo (int) $tab['category_id']; ?>" data-cat="<?php echo (int) $tab['category_id']; ?>"
data-tab-count="<?php echo (int) $tab['count']; ?>" data-tab-count="<?php echo (int) $tab['count']; ?>"
data-topics="<?php echo esc_attr((string) ($tab['topics'] ?? '')); ?>"
data-limit-day="<?php echo esc_attr((string) ((int) ($tab['limit_day'] ?? 0))); ?>"
data-pay-type="<?php echo esc_attr((string) ($tab['pay_type'] ?? '')); ?>"
aria-selected="<?php echo $first ? 'true' : 'false'; ?>" aria-selected="<?php echo $first ? 'true' : 'false'; ?>"
><?php echo esc_html($tab_title); ?></button> ><?php echo esc_html($tab_title); ?></button>
</li> </li>
@@ -295,7 +301,7 @@ class TabPostsWidget extends \WP_Widget {
$max_tabs = 8; $max_tabs = 8;
$tabs = array_slice($tabs, 0, $max_tabs); $tabs = array_slice($tabs, 0, $max_tabs);
while (count($tabs) < 3) { while (count($tabs) < 3) {
$tabs[] = ['title' => '', 'category_id' => 0, 'orderby' => 'date', 'count' => 0, 'enabled' => false]; $tabs[] = ['title' => '', 'category_id' => 0, 'orderby' => 'date', 'count' => 0, 'topics' => '', 'limit_day' => 0, 'pay_type' => '', 'enabled' => false];
} }
foreach ($tabs as $i => $tab) : foreach ($tabs as $i => $tab) :
?> ?>
@@ -323,6 +329,23 @@ class TabPostsWidget extends \WP_Widget {
<label><?php esc_html_e('数量(0=使用默认):', 'aksrt'); ?></label> <label><?php esc_html_e('数量(0=使用默认):', 'aksrt'); ?></label>
<input class="tiny-text" type="number" min="0" max="20" name="<?php echo esc_attr($this->get_field_name("tabs[{$i}][count]")); ?>" value="<?php echo (int) $tab['count']; ?>"> <input class="tiny-text" type="number" min="0" max="20" name="<?php echo esc_attr($this->get_field_name("tabs[{$i}][count]")); ?>" value="<?php echo (int) $tab['count']; ?>">
</p> </p>
<p style="margin:0 0 6px;">
<label><?php esc_html_e('专题 topics ID(逗号):', 'aksrt'); ?></label>
<input class="widefat" type="text" name="<?php echo esc_attr($this->get_field_name("tabs[{$i}][topics]")); ?>" value="<?php echo esc_attr((string) ($tab['topics'] ?? '')); ?>">
</p>
<p style="margin:0 0 6px;">
<label><?php esc_html_e('最近 N 天(0=不限):', 'aksrt'); ?></label>
<input class="tiny-text" type="number" min="0" name="<?php echo esc_attr($this->get_field_name("tabs[{$i}][limit_day]")); ?>" value="<?php echo (int) ($tab['limit_day'] ?? 0); ?>">
</p>
<p style="margin:0;">
<label><?php esc_html_e('付费类型:', 'aksrt'); ?></label>
<select class="widefat" name="<?php echo esc_attr($this->get_field_name("tabs[{$i}][pay_type]")); ?>">
<option value="" <?php selected(($tab['pay_type'] ?? ''), ''); ?>><?php esc_html_e('不限', 'aksrt'); ?></option>
<option value="paid" <?php selected(($tab['pay_type'] ?? ''), 'paid'); ?>><?php esc_html_e('任意付费', 'aksrt'); ?></option>
<option value="reading" <?php selected(($tab['pay_type'] ?? ''), 'reading'); ?>><?php esc_html_e('付费阅读', 'aksrt'); ?></option>
<option value="download" <?php selected(($tab['pay_type'] ?? ''), 'download'); ?>><?php esc_html_e('付费下载', 'aksrt'); ?></option>
</select>
</p>
</div> </div>
<?php endforeach; <?php endforeach;
} }