导入 AKSRT 主题开发源码
This commit is contained in:
1 parent
9681dd3d48
commit
1268a55dd0
595 files changed
+127705
No files matched your search
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
/**
|
||||
* 用户中心 — 我的收藏
|
||||
*
|
||||
* @package AKSRT
|
||||
* @since 5.0.0
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
$per_page = 10;
|
||||
$paged = max(1, get_query_var('paged'));
|
||||
|
||||
$favorite_ids = get_user_meta($user_id, 'aksrt_favorite_posts', true);
|
||||
$favorite_ids = is_array($favorite_ids) ? $favorite_ids : [];
|
||||
$total = count($favorite_ids);
|
||||
|
||||
// 分页切片
|
||||
$offset = ($paged - 1) * $per_page;
|
||||
$page_ids = array_slice($favorite_ids, $offset, $per_page);
|
||||
$max_pages = ceil($total / $per_page);
|
||||
?>
|
||||
|
||||
<div class="uc-favorites" id="uc-favorites">
|
||||
<?php if (!empty($page_ids)) : ?>
|
||||
<div class="uc-favorites__list">
|
||||
<?php foreach ($page_ids as $fid) :
|
||||
$post = get_post((int) $fid);
|
||||
if (!$post || $post->post_status !== 'publish') continue;
|
||||
?>
|
||||
<div class="uc-favorites__item">
|
||||
<div class="uc-favorites__content">
|
||||
<h4 class="uc-favorites__title">
|
||||
<a href="<?php echo esc_url(get_permalink($post->ID)); ?>"><?php echo esc_html($post->post_title); ?></a>
|
||||
</h4>
|
||||
<div class="uc-favorites__meta">
|
||||
<span><i class="far fa-clock"></i> <?php echo esc_html(get_the_date('Y-m-d', $post->ID)); ?></span>
|
||||
<span><i class="far fa-eye"></i> <?php echo esc_html(get_post_meta($post->ID, 'aksrt_post_views', true) ?: 0); ?></span>
|
||||
</div>
|
||||
<button class="uc-favorites__remove" data-action="remove-favorite" data-post-id="<?php echo esc_attr($post->ID); ?>">
|
||||
<i class="fas fa-heart-broken"></i> <?php esc_html_e('取消收藏', 'aksrt'); ?>
|
||||
</button>
|
||||
</div>
|
||||
<?php if (has_post_thumbnail($post->ID)) : ?>
|
||||
<a href="<?php echo esc_url(get_permalink($post->ID)); ?>" class="uc-favorites__thumb">
|
||||
<?php echo get_the_post_thumbnail($post->ID, 'thumbnail'); ?>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
||||
<?php if ($max_pages > 1) : ?>
|
||||
<div class="aksrt-pagination">
|
||||
<?php
|
||||
echo paginate_links([
|
||||
'base' => str_replace(999999999, '%#%', esc_url(get_pagenum_link(999999999))),
|
||||
'format' => '?paged=%#%',
|
||||
'current' => $paged,
|
||||
'total' => $max_pages,
|
||||
'prev_text' => '<i class="fas fa-chevron-left"></i>',
|
||||
'next_text' => '<i class="fas fa-chevron-right"></i>',
|
||||
]);
|
||||
?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php else : ?>
|
||||
<div class="empty-state empty-state--sm">
|
||||
<div class="empty-state__icon"><i class="far fa-heart"></i></div>
|
||||
<p class="empty-state__title"><?php esc_html_e('暂无收藏', 'aksrt'); ?></p>
|
||||
<p class="empty-state__desc"><?php esc_html_e('看到喜欢的文章,点击收藏按钮即可保存~', 'aksrt'); ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
Reference in new issue
Block a user