现在首页每篇文章都是一个大标题加一整篇正文,一屏放不下两篇。列表应该像目录,不像正文。
一个列表项,通常三样东西:标题、一小段摘要、一行元信息。
把 the_content() 换成 the_excerpt()。摘要默认截 55 个词,末尾带 [...]。下一篇专门处理它。
the_time():日期。别用 the_date(),它同一天只输出第一篇。the_author():作者名。the_category():分类,自动带链接,不用自己包 a。<article>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="meta">
<?php the_time( get_option( 'date_format' ) ); ?> ·
<?php the_author(); ?> ·
<?php the_category( ', ' ); ?>
</p>
<?php the_excerpt(); ?>
</article>
外面套 <article> 是语义标签,告诉浏览器「这是一篇独立的内容」。第四轮写样式时,靠 article 和 .meta 这两个选择器就能分开处理。
标题外面要有 <a> 包着 the_permalink(),不然读者点不进文章。第一轮第三篇已经改过一次,现在这个循环是完整的。
下一篇:摘要为什么总是太长,还挂着个 [...]。
本系列:迭代式建主题 · 目录(72 篇) | 上一篇 (13) | 下一篇 (15)