64 lines
1.5 KiB
PHP
64 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* Home Module · Recent
|
|
*
|
|
* config: { count, layout, title? }
|
|
* Lists ordinary posts only (no content-type split).
|
|
*/
|
|
defined('ABSPATH') || exit;
|
|
|
|
$cfg = get_query_var('aksrt_module_config', []);
|
|
if (!is_array($cfg)) {
|
|
$cfg = [];
|
|
}
|
|
|
|
$count = max(1, min(20, (int) ($cfg['count'] ?? 6)));
|
|
$layout = (string) ($cfg['layout'] ?? 'card');
|
|
$title = (string) ($cfg['title'] ?? '');
|
|
|
|
if (!in_array($layout, ['card', 'list'], true)) {
|
|
$layout = 'card';
|
|
}
|
|
|
|
$args = [
|
|
'post_type' => 'post',
|
|
'posts_per_page' => $count,
|
|
'post_status' => 'publish',
|
|
'no_found_rows' => true,
|
|
'orderby' => 'date',
|
|
'order' => 'DESC',
|
|
];
|
|
|
|
$query = new WP_Query($args);
|
|
if (!$query->have_posts()) {
|
|
wp_reset_postdata();
|
|
return;
|
|
}
|
|
|
|
$display_title = $title ?: __('最新文章', 'aksrt');
|
|
$archive_link = get_permalink(get_option('page_for_posts'));
|
|
?>
|
|
|
|
<section class="home-module home-module--recent container" aria-label="<?php echo esc_attr($display_title); ?>">
|
|
<header class="home-module__header">
|
|
<h2 class="home-module__title"><?php echo esc_html($display_title); ?></h2>
|
|
<?php if ($archive_link) : ?>
|
|
<a class="home-module__more" href="<?php echo esc_url($archive_link); ?>">
|
|
<?php esc_html_e('查看更多', 'aksrt'); ?> <i class="fas fa-arrow-right" aria-hidden="true"></i>
|
|
</a>
|
|
<?php endif; ?>
|
|
</header>
|
|
|
|
<div class="posts-row ajaxpager">
|
|
<?php
|
|
aksrt_render_post_list([
|
|
'type' => $layout === 'card' ? 'card' : 'list',
|
|
'is_home' => true,
|
|
'skip_wrapper' => true,
|
|
], $query);
|
|
?>
|
|
</div>
|
|
</section>
|
|
<?php
|
|
wp_reset_postdata();
|