Files
wordpress-theme-aksrt/templates/forum/forum-plate-cat.php
T

108 lines
4.8 KiB
PHP

<?php
/**
* Plate category (分区) archive template.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
get_header();
$forum = class_exists('AKSRT_Forum') ? AKSRT_Forum::get_instance() : null;
$term = get_queried_object();
$cat_id = $term ? (int) $term->term_id : 0;
$forum_settings = class_exists('AKSRT_Settings') ? AKSRT_Settings::get_forum_settings() : [];
$forum_names = $forum_settings['names'] ?? [];
$forum_name = $forum_names['forum'] ?? __('论坛', 'aksrt');
$plates = [];
if ($forum && $cat_id > 0) {
$plates = $forum->get_sorted_plates('menu_order', 'ASC', 100);
$plates = array_filter($plates, static function ($plate) use ($cat_id): bool {
return isset($plate['plate_cat']['id']) && (int) $plate['plate_cat']['id'] === $cat_id;
});
$plates = array_values($plates);
}
$cat_moderator_ids = get_term_meta($cat_id, '_aksrt_cat_moderator', true);
$cat_moderators = [];
if (is_array($cat_moderator_ids)) {
foreach ($cat_moderator_ids as $uid) {
$user = get_userdata((int) $uid);
if ($user) {
$cat_moderators[] = [
'id' => (int) $user->ID,
'name' => $user->display_name,
'avatar' => function_exists('aksrt_get_avatar_url') ? aksrt_get_avatar_url($user->ID, 36) : get_avatar_url($user->ID, ['size' => 36]),
];
}
}
}
?>
<main id="main-content" class="site-main content-shell" tabindex="-1">
<?php if (function_exists('aksrt_breadcrumbs')) { aksrt_breadcrumbs(); } ?>
<div class="aksrt-forum-plate-cat container">
<div class="aksrt-forum-plate-cat__header">
<h1><?php echo esc_html($term ? $term->name : ''); ?></h1>
<?php if ($term && $term->description) : ?>
<p><?php echo esc_html($term->description); ?></p>
<?php endif; ?>
<?php if (!empty($cat_moderators)) : ?>
<div class="aksrt-forum-plate-cat__moderators">
<span><?php esc_html_e('分区版主:', 'aksrt'); ?></span>
<?php foreach ($cat_moderators as $mod) : ?>
<span class="aksrt-forum-plate-cat__moderator">
<?php if (!empty($mod['avatar'])) : ?>
<img src="<?php echo esc_url($mod['avatar']); ?>" alt="" width="24" height="24">
<?php endif; ?>
<?php echo esc_html($mod['name']); ?>
</span>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<div class="aksrt-forum-plate-cat__plates">
<?php if (!empty($plates)) : ?>
<?php foreach ($plates as $plate) : ?>
<a href="<?php echo esc_url((string) ($plate['url'] ?? '#')); ?>" class="aksrt-forum-plate-cat__plate-card">
<?php if (!empty($plate['cover_url'])) : ?>
<img class="aksrt-forum-plate-cat__plate-cover" src="<?php echo esc_url($plate['cover_url']); ?>" alt="" loading="lazy">
<?php elseif (!empty($plate['icon'])) : ?>
<div class="aksrt-forum-plate-cat__plate-icon"><i class="<?php echo esc_attr($plate['icon']); ?>"></i></div>
<?php endif; ?>
<div class="aksrt-forum-plate-cat__plate-info">
<h3><?php echo esc_html((string) ($plate['name'] ?? '')); ?></h3>
<p><?php echo esc_html((string) ($plate['description'] ?? '')); ?></p>
<div class="aksrt-forum-plate-cat__plate-meta">
<span><?php printf(esc_html__('%d 主题', 'aksrt'), (int) ($plate['post_count'] ?? 0)); ?></span>
<span><?php printf(esc_html__('%d 关注', 'aksrt'), (int) ($plate['follow_count'] ?? 0)); ?></span>
<?php if (!empty($plate['is_hot'])) : ?>
<span class="aksrt-forum-plate-cat__hot-badge"><?php esc_html_e('热门', 'aksrt'); ?></span>
<?php endif; ?>
</div>
</div>
</a>
<?php endforeach; ?>
<?php else : ?>
<div class="aksrt-forum-plate-cat__empty">
<p><?php esc_html_e('该分区暂无版块。', 'aksrt'); ?></p>
</div>
<?php endif; ?>
</div>
<div class="aksrt-forum-plate-cat__back">
<a href="<?php echo esc_url(home_url('/forums/')); ?>">
<i class="fas fa-arrow-left"></i> <?php printf(esc_html__('返回%s', 'aksrt'), esc_html($forum_name)); ?>
</a>
</div>
</div>
</main>
<?php get_footer(); ?>