feat(widgets): zibll-like in_affix sticky option across side modules

Add sidebar affix (data-affix) to ranking, user/author cards, main/hot/
paid/forum lists, comments, tag cloud, categories and text title with
shared sticky CSS.
This commit is contained in:
kate522 committed 2026-07-21 13:55:16 +08:00
1 parent 53bdd632d0
commit 93833ad381
13 files changed
+115 -12

No files matched your search

+10 -1
View File
@@ -29,12 +29,14 @@ class WidgetUserRanking extends \WP_Widget {
$show_avatar = !isset($instance['show_avatar']) || !empty($instance['show_avatar']);
$desc_mode = sanitize_key((string) ($instance['desc'] ?? 'desc'));
$top_badge = !empty($instance['top_badge']);
$in_affix = !empty($instance['in_affix']);
$users = $this->get_ranking($rank_by, $count, $desc_mode);
echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $args['before_title'] . esc_html($title) . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo '<div class="zib-widget user-ranking-box aksrt-user-ranking-box">';
$box_cls = 'zib-widget user-ranking-box aksrt-user-ranking-box' . ($in_affix ? ' is-affix' : '');
echo '<div class="' . esc_attr($box_cls) . '"' . ($in_affix ? ' data-affix="true"' : '') . '>';
if (!empty($instance['checkin_btn']) && is_user_logged_in() && function_exists('aksrt_header_user_checkin_btn')) {
$cbtn = aksrt_header_user_checkin_btn(get_current_user_id());
if ($cbtn !== '') {
@@ -336,6 +338,12 @@ class WidgetUserRanking extends \WP_Widget {
<?php esc_html_e('前三名 TOP 角标', 'aksrt'); ?>
</label>
</p>
<p>
<label>
<input type="checkbox" name="<?php echo esc_attr($this->get_field_name('in_affix')); ?>" value="1" <?php checked(!empty($instance['in_affix'])); ?>>
<?php esc_html_e('侧栏随动', 'aksrt'); ?>
</label>
</p>
<?php
}
@@ -348,6 +356,7 @@ class WidgetUserRanking extends \WP_Widget {
$instance['checkin_btn'] = !empty($new_instance['checkin_btn']) ? 1 : 0;
$instance['top_badge'] = !empty($new_instance['top_badge']) ? 1 : 0;
$instance['desc'] = in_array($new_instance['desc'] ?? '', ['desc', 'user_registered', 'last_login', 'last_checkin'], true) ? $new_instance['desc'] : 'desc';
$instance['in_affix'] = !empty($new_instance['in_affix']) ? 1 : 0;
return $instance;
}
}