导入 AKSRT 主题开发源码
This commit is contained in:
1 parent
9681dd3d48
commit
1268a55dd0
595 files changed
+127705
No files matched your search
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* Shortcode template: [aksrt_archive]
|
||||
*
|
||||
* 紧凑版文章归档(按年月分组)。供 AKSRT_Shortcodes::render_archive() 通过
|
||||
* AKSRT_Templates::render_archive_shortcode() 以输出缓冲方式 include。
|
||||
*
|
||||
* 可用变量:$attrs(短代码属性)、$content。
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$limit = isset($attrs['limit']) ? max(0, (int) $attrs['limit']) : 0; // 0 = 全部
|
||||
|
||||
$rows = $wpdb->get_results(
|
||||
"SELECT DISTINCT YEAR(post_date) AS year, MONTH(post_date) AS month, COUNT(*) AS count
|
||||
FROM {$wpdb->posts}
|
||||
WHERE post_type = 'post' AND post_status = 'publish'
|
||||
GROUP BY YEAR(post_date), MONTH(post_date)
|
||||
ORDER BY year DESC, month DESC"
|
||||
); // phpcs:ignore WordPress.DB.DirectDatabaseQuery
|
||||
|
||||
if (empty($rows)) {
|
||||
echo '<div class="aksrt-archives aksrt-archives--shortcode aksrt-archives--empty">'
|
||||
. esc_html__('暂无文章。', 'aksrt') . '</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
$current_year = 0;
|
||||
$shown = 0;
|
||||
?>
|
||||
<div class="aksrt-archives aksrt-archives--shortcode">
|
||||
<?php foreach ($rows as $row) :
|
||||
if ((int) $row->year !== $current_year) :
|
||||
$current_year = (int) $row->year;
|
||||
?>
|
||||
<h2 class="aksrt-archives__year"><?php echo esc_html((string) $current_year); ?></h2>
|
||||
<?php endif; ?>
|
||||
<h3 class="aksrt-archives__month"><?php echo esc_html(sprintf(__('%1$d 月(%2$d 篇)', 'aksrt'), (int) $row->month, (int) $row->count)); ?></h3>
|
||||
<ul class="aksrt-archives__list">
|
||||
<?php
|
||||
$month_posts = get_posts([
|
||||
'year' => (int) $row->year,
|
||||
'monthnum' => (int) $row->month,
|
||||
'posts_per_page' => -1,
|
||||
'post_status' => 'publish',
|
||||
'no_found_rows' => true,
|
||||
]);
|
||||
foreach ($month_posts as $mp) :
|
||||
if ($limit > 0 && $shown >= $limit) {
|
||||
break;
|
||||
}
|
||||
$shown++;
|
||||
?>
|
||||
<li class="aksrt-archives__item">
|
||||
<span class="aksrt-archives__date"><?php echo esc_html(get_the_date('m-d', $mp)); ?></span>
|
||||
<a href="<?php echo esc_url(get_permalink($mp->ID)); ?>" class="aksrt-archives__link"><?php echo esc_html(get_the_title($mp)); ?></a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php if ($limit > 0 && $shown >= $limit) { break; } ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* Shortcode template: [aksrt_profile]
|
||||
*
|
||||
* 当前登录用户的资料卡。供 AKSRT_Shortcodes::render_profile() 通过
|
||||
* AKSRT_Templates::render_profile_shortcode() 以输出缓冲方式 include。
|
||||
*
|
||||
* 可用变量:$attrs(短代码属性,支持 user="<ID 或 login>" 指定用户)、$content。
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
// 解析目标用户:属性指定 > 当前登录用户。
|
||||
$target = isset($attrs['user']) ? trim((string) $attrs['user']) : '';
|
||||
$user = null;
|
||||
if ($target !== '') {
|
||||
$user = is_numeric($target) ? get_user_by('id', (int) $target) : get_user_by('login', $target);
|
||||
} elseif (is_user_logged_in()) {
|
||||
$user = wp_get_current_user();
|
||||
}
|
||||
|
||||
if (!($user instanceof WP_User) || $user->ID <= 0) {
|
||||
echo '<div class="aksrt-profile-card aksrt-profile-card--shortcode aksrt-profile-card--guest">'
|
||||
. '<p>' . esc_html__('登录后查看个人资料。', 'aksrt') . '</p>';
|
||||
if (function_exists('aksrt_get_login_url')) {
|
||||
echo '<a class="btn-primary btn-sm" href="' . esc_url(aksrt_get_login_url()) . '">' . esc_html__('登录', 'aksrt') . '</a>';
|
||||
}
|
||||
echo '</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
$user_id = (int) $user->ID;
|
||||
$avatar = function_exists('aksrt_get_avatar_url') ? aksrt_get_avatar_url($user_id, ['size' => 96]) : get_avatar_url($user_id, ['size' => 96]);
|
||||
$home_url = function_exists('aksrt_get_user_home_url') ? aksrt_get_user_home_url($user) : get_author_posts_url($user_id);
|
||||
$credits = function_exists('aksrt_user_credits') ? (int) aksrt_user_credits($user_id) : 0;
|
||||
$post_count = (int) count_user_posts($user_id, 'post', true);
|
||||
$bio = (string) get_the_author_meta('description', $user_id);
|
||||
$show_credits = class_exists('AKSRT_Settings') ? AKSRT_Settings::credits_enabled() : true;
|
||||
?>
|
||||
<div class="aksrt-profile-card aksrt-profile-card--shortcode">
|
||||
<a class="aksrt-profile-card__avatar" href="<?php echo esc_url($home_url); ?>">
|
||||
<img src="<?php echo esc_url($avatar); ?>" alt="<?php echo esc_attr($user->display_name); ?>" width="64" height="64"<?php echo function_exists('aksrt_lazy_loading') ? aksrt_lazy_loading('avatar') : ' loading="lazy"'; ?>>
|
||||
</a>
|
||||
<div class="aksrt-profile-card__body">
|
||||
<a class="aksrt-profile-card__name" href="<?php echo esc_url($home_url); ?>"><?php echo esc_html($user->display_name); ?></a>
|
||||
<?php if ($bio !== '') : ?>
|
||||
<p class="aksrt-profile-card__bio"><?php echo esc_html(wp_trim_words($bio, 24, '…')); ?></p>
|
||||
<?php endif; ?>
|
||||
<div class="aksrt-profile-card__stats">
|
||||
<span class="aksrt-profile-card__stat"><strong><?php echo esc_html(number_format_i18n($post_count)); ?></strong><?php esc_html_e('文章', 'aksrt'); ?></span>
|
||||
<?php if ($show_credits) : ?>
|
||||
<span class="aksrt-profile-card__stat"><strong><?php echo esc_html(number_format_i18n($credits)); ?></strong><?php esc_html_e('积分', 'aksrt'); ?></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
Reference in new issue
Block a user