If you’re working with the Site Editor (block-based theme) and HTML templates, here’s how you can show just a part of the post content (like an excerpt) in your archive or category pages:
1. Edit the Template Using Site Editor
- Go to the Site Editor:
- From your WordPress dashboard, go to Appearance > Editor
- Example : my site editor URL is https://nathabee.de/wordpress/wp-admin/site-editor.php
- Navigate to the Archive Template:
- In the Site Editor, click the W icon (top-left) > Templates.
- Select the Archive template (or the template being used for your category page).
- Find the Post Content Block:
- In the Archive template, locate the block that displays post content. This is usually a Post Content block inside a Query Loop block.
- Customize the Content Display:
- Click on the Post Content block.
- In the block settings (right-hand panel), you can toggle the option to display the Excerpt instead of the full content:
- Find the “Excerpt” option.
- Toggle it on.
2. Edit the Block-Based HTML Files
If you want to manually modify the template file that renders the archive page, you can edit the corresponding HTML template file in your theme.
It is possible to access and modify the template using the theme-editor (example on https://nathabee.de/wordpress/wp-admin/theme-editor.php) or directly on the server (example : access the server with ssh and edit the file it with nano )
- Locate the Template File:
- For a category archive, the file will be something like
/wp-content/themes/your-theme/block-templates/archive.html
or/category.html
.
- For a category archive, the file will be something like
- Modify the Post Content Block in the HTML File: Open the template file (e.g.,
archive.html
) in a text editor or the Site Editor and locate the block for the Post Content. It should look something like this:<!-- wp:query {"queryId":1,"query":{"perPage":10,"offset":0,"postType":"post","order":"desc","orderBy":"date"}} --> <div class="wp-block-query"> <!-- wp:post-template --> <!-- wp:post-title /--> <!-- wp:post-excerpt /--> <!-- /wp:post-template --> </div> <!-- /wp:query -->
- Replace
Post Content
withPost Excerpt
: Replace the<!-- wp:post-content /-->
block with<!-- wp:post-excerpt /-->
to display the excerpt instead of the full content. Example:<!-- wp:post-template --> <!-- wp:post-title /--> <!-- wp:post-excerpt {"moreText":"Read More"} /--> <!-- /wp:post-template -->
- Save and Test:
- Save your changes and refresh the category/archive page on your site to verify the output.
3. Customize the Excerpt Length
You can customize the length of the excerpt by adding the following code to your functions.php file in your child theme:
function custom_excerpt_length($length) {
return 20; // Number of words in the excerpt
}
add_filter('excerpt_length', 'custom_excerpt_length', 999);
4. Add a “Read More” Link
If you want to add a “Read More” link after the excerpt in the block editor:
- Go to the Post Excerpt block settings in the Site Editor.
- Use the option to display “Read More” and set the text.
Alternatively, if you’re editing the HTML template:
<!-- wp:post-excerpt {"moreText":"Continue Reading"} /-->
Summary
If you’re using the Site Editor:
- Use the Post Excerpt block in the Query Loop block instead of the Post Content block.
- Adjust the settings via the block options or edit the HTML template.
If you’re working directly with templates:
- Use the
post-excerpt
block in the relevant block-based HTML file.
Let me know if you encounter any issues!
Leave a Reply