Using Excerpts to Display Content on Archive Pages


Excerpts in WordPress are a concise summary of your posts' content. They are commonly used to provide a brief preview of a post's content on archive pages such as category, tag, or search result pages. In this guide, we'll explore what excerpts are and how to use them effectively on your WordPress site using sample HTML code.


Understanding Excerpts

Excerpts are manually written summaries of your posts, typically located in the "Excerpt" box below the post editor in the WordPress dashboard. If you don't provide an excerpt, WordPress will automatically generate one based on the first few sentences of your post.


Sample HTML Code for Using Excerpts

To display excerpts on archive pages, you typically need to modify your theme's template files, such as archive.php or category.php. Below is a sample code snippet demonstrating how to display excerpts in an archive page:

        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<div class="excerpt">
<?php the_excerpt(); ?>
</div>
</div>
<?php endwhile; else: ?>
<p>No posts were found.</p>
<?php endif; ?>

Customizing Excerpts

You can customize how excerpts are displayed by modifying your theme's CSS to style the "excerpt" class or by creating a custom function in your theme's functions.php file to control the length and formatting of the excerpts.


Conclusion

Using excerpts in WordPress is a great way to provide a preview of your content on archive pages, making it easier for visitors to scan and find relevant posts. By using the sample HTML code provided and customizing your theme's excerpts, you can enhance the user experience and encourage users to explore your content further.