<?php
/**
* 主页模板 (index.php)
*
* 这是WordPress主题中最重要的模板文件,用于显示网站的主页内容
* 当没有更具体的模板可用时,WordPress会使用这个文件
*
* @package sUx
*/
get_header(); // 加载网站头部
?>
<div class="site-container">
<div class="site-main">
<div class="content-area">
<?php if (is_home() && !is_front_page()) : ?>
<!-- 如果是博客页面但不是首页,显示页面标题 -->
<header class="page-header">
<h1 class="page-title sux-primary-color">
<?php single_post_title(); ?>
</h1>
</header>
<?php endif; ?>
<div class="post-list">
<?php if (have_posts()) : ?>
<?php
/**
* 开始文章循环
* have_posts() 检查是否还有文章
* the_post() 设置当前文章数据
*/
?>
<?php while (have_posts()) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class('post'); ?>>
<!-- 文章特色图片 -->
<?php if (has_post_thumbnail()) : ?>
<div class="post-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php
// 显示特色图片,设置为中等尺寸
the_post_thumbnail('medium', array(
'class' => 'featured-image',
'alt' => get_the_title()
));
?>
</a>
</div>
<?php endif; ?>
<!-- 文章内容区域 -->
<div class="post-content">
<!-- 文章标题 -->
<header class="entry-header">
<h2 class="entry-title">
<a href="<?php the_permalink(); ?>" rel="bookmark">
<?php the_title(); ?>
</a>
</h2>
</header>
<!-- 文章元信息(作者、日期、分类等) -->
<div class="entry-meta">
<!-- 作者信息 -->
<span class="author">
<i class="fas fa-user"></i>
<?php
// 显示作者链接
the_author_posts_link();
?>
</span>
<!-- 发布日期 -->
<span class="posted-on">
<i class="fas fa-calendar"></i>
<time class="entry-date published" datetime="<?php echo get_the_date('c'); ?>">
<?php
// 显示发布日期,格式为:年月日
echo get_the_date('Y年m月d日');
?>
</time>
</span>
<!-- 分类信息 -->
<span class="cat-links">
<i class="fas fa-folder"></i>
<?php
// 显示文章分类,用逗号分隔
the_category(', ');
?>
</span>
<!-- 评论数 -->
<?php if (!post_password_required() && (comments_open() || get_comments_number())) : ?>
<span class="comments-link">
<i class="fas fa-comments"></i>
<?php
// 显示评论数量,带链接
comments_popup_link(
__('暂无评论', 'sux'),
__('1 条评论', 'sux'),
__('% 条评论', 'sux')
);
?>
</span>
<?php endif; ?>
</div>
<!-- 文章摘要 -->
<div class="entry-excerpt">
<?php
/**
* 显示文章摘要
* 如果设置了文章摘要则显示摘要,否则自动截取文章内容
*/
the_excerpt();
?>
</div>
<!-- 继续阅读链接 -->
<div class="read-more-container">
<a href="<?php the_permalink(); ?>" class="read-more">
<?php _e('继续阅读', 'sux'); ?> →
</a>
</div>
</div>
</article>
<?php endwhile; ?>
<!-- 分页导航 -->
<?php
/**
* 显示分页导航
* 使用主题自带的分页函数,支持数字分页
*/
the_posts_pagination(array(
'mid_size' => 2, // 当前页两侧显示的页码数
'prev_text' => __('上一页', 'sux'),
'next_text' => __('下一页', 'sux'),
'screen_reader_text' => __('文章导航', 'sux'),
'before_page_number' => '<span class="page-number">',
'after_page_number' => '</span>',
));
?>
<?php else : ?>
<!-- 没有找到文章时的提示 -->
<div class="no-posts-found">
<div class="no-posts-content">
<h2 class="sux-primary-color"><?php _e('没有找到文章', 'sux'); ?></h2>
<p><?php _e('抱歉,没有找到符合要求的文章。请尝试其他搜索关键词或浏览分类。', 'sux'); ?></p>
<!-- 搜索表单 -->
<?php get_search_form(); ?>
</div>
</div>
<?php endif; ?>
</div>
</div>
<!-- 侧边栏 -->
<?php get_sidebar(); ?>
</div>
</div>
<?php get_footer(); // 加载网站页脚 ?>