导入 AKSRT 主题开发源码
This commit is contained in:
1 parent
9681dd3d48
commit
1268a55dd0
595 files changed
+127705
No files matched your search
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
/**
|
||||
* Home Module · User Cards
|
||||
*
|
||||
* Maps to zibll widget-user capability.
|
||||
* config: { title?, count, columns, order(recent/posts/manual), user_ids[], show_stats }
|
||||
*/
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
$cfg = get_query_var('aksrt_module_config', []);
|
||||
if (!is_array($cfg)) {
|
||||
$cfg = [];
|
||||
}
|
||||
|
||||
$title = trim((string) ($cfg['title'] ?? ''));
|
||||
$count = max(1, min(12, (int) ($cfg['count'] ?? 4)));
|
||||
$columns = max(2, min(6, (int) ($cfg['columns'] ?? 4)));
|
||||
$order = sanitize_key((string) ($cfg['order'] ?? 'recent'));
|
||||
$user_ids = isset($cfg['user_ids']) && is_array($cfg['user_ids']) ? array_map('absint', $cfg['user_ids']) : [];
|
||||
$show_stats = !isset($cfg['show_stats']) || !empty($cfg['show_stats']);
|
||||
|
||||
// Build user query.
|
||||
if ($order === 'manual' && !empty($user_ids)) {
|
||||
$query_args = [
|
||||
'include' => array_slice($user_ids, 0, $count),
|
||||
'orderby' => 'include',
|
||||
'number' => $count,
|
||||
];
|
||||
} elseif ($order === 'posts') {
|
||||
$query_args = [
|
||||
'number' => $count,
|
||||
'orderby' => 'post_count',
|
||||
'order' => 'DESC',
|
||||
];
|
||||
} else {
|
||||
// 'recent' = newest registrations.
|
||||
$query_args = [
|
||||
'number' => $count,
|
||||
'orderby' => 'registered',
|
||||
'order' => 'DESC',
|
||||
];
|
||||
}
|
||||
|
||||
$users = get_users($query_args);
|
||||
if (empty($users)) {
|
||||
return;
|
||||
}
|
||||
?>
|
||||
|
||||
<section class="home-module home-module--users container" aria-label="<?php echo esc_attr($title ?: __('推荐用户', 'aksrt')); ?>">
|
||||
<header class="home-module__header">
|
||||
<h2 class="home-module__title"><?php echo esc_html($title ?: __('推荐用户', 'aksrt')); ?></h2>
|
||||
</header>
|
||||
|
||||
<div class="home-module__users-grid" style="--cols: <?php echo (int) $columns; ?>;">
|
||||
<?php foreach ($users as $user) :
|
||||
$uid = $user->ID;
|
||||
$avatar = get_avatar_url($uid, ['size' => 96]);
|
||||
$display = $user->display_name ?: $user->user_login;
|
||||
$bio = get_user_meta($uid, 'description', true);
|
||||
$post_cnt = count_user_posts($uid);
|
||||
$profile = function_exists('aksrt_get_user_home_url')
|
||||
? aksrt_get_user_home_url($uid)
|
||||
: get_author_posts_url($uid);
|
||||
?>
|
||||
<div class="home-module__user-card">
|
||||
<a href="<?php echo esc_url($profile); ?>" class="home-module__user-link">
|
||||
<img src="<?php echo esc_url($avatar); ?>" alt="" class="home-module__user-avatar"<?php echo function_exists('aksrt_lazy_loading') ? aksrt_lazy_loading('other') : ' loading="lazy"'; ?>>
|
||||
<strong class="home-module__user-name"><?php echo esc_html($display); ?></strong>
|
||||
</a>
|
||||
<?php if ($bio) : ?>
|
||||
<p class="home-module__user-bio"><?php echo esc_html(wp_trim_words($bio, 12, '...')); ?></p>
|
||||
<?php endif; ?>
|
||||
<?php if ($show_stats) : ?>
|
||||
<span class="home-module__user-stats">
|
||||
<span class="home-module__user-stat">
|
||||
<i class="fas fa-file-alt" aria-hidden="true"></i>
|
||||
<?php echo (int) $post_cnt; ?>
|
||||
</span>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</section>
|
||||
Reference in new issue
Block a user