Files
wordpress-theme-aksrt/templates/parts/user-shared-helpers.php
T

60 lines
2.2 KiB
PHP

<?php
/**
* 用户页面共享辅助函数
*
* 分页渲染和空状态卡片,供本人中心和公开主页共用。
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
if (!function_exists('aksrt_render_profile_pagination')) {
/**
* 渲染分页
*
* @param int $total_pages 总页数
* @param int $current 当前页
* @param string $param URL 参数名
*/
function aksrt_render_profile_pagination($total_pages, $current, $param, $base_url = '') {
if ($total_pages <= 1) {
return;
}
$base = $base_url !== '' ? $base_url : remove_query_arg($param);
$base = remove_query_arg($param, $base);
$base = add_query_arg($param, '%#%', $base);
$links = paginate_links([
'base' => $base,
'format' => '',
'current' => $current,
'total' => $total_pages,
'prev_text' => '<span aria-hidden="true">&lsaquo;</span><span class="screen-reader-text">' . esc_html__('上一页', 'aksrt') . '</span>',
'next_text' => '<span aria-hidden="true">&rsaquo;</span><span class="screen-reader-text">' . esc_html__('下一页', 'aksrt') . '</span>',
'mid_size' => 1,
'end_size' => 1,
]);
if ($links) {
echo '<nav class="profile-pagination" aria-label="' . esc_attr__('分页', 'aksrt') . '">' . $links . '</nav>'; // phpcs:ignore
}
}
}
if (!function_exists('aksrt_render_profile_empty')) {
/**
* 渲染空状态卡片
*/
function aksrt_render_profile_empty($icon_svg, $title, $desc = '', $cta_url = '', $cta_label = '') {
echo '<div class="profile-empty">';
echo '<div class="profile-empty__icon" aria-hidden="true">' . $icon_svg . '</div>'; // phpcs:ignore
echo '<h4 class="profile-empty__title">' . esc_html($title) . '</h4>';
if ($desc) {
echo '<p class="profile-empty__desc">' . esc_html($desc) . '</p>';
}
if ($cta_url && $cta_label) {
echo '<a class="btn-primary btn-sm profile-empty__cta" href="' . esc_url($cta_url) . '">' . esc_html($cta_label) . '</a>';
}
echo '</div>';
}
}