From version 126.96.36.199 of Magento WordPress Integration, it is now possible to easily shorten your post content to create an automatic excerpt for each post. If you have a version of the extension that is older than version 188.8.131.52, you will need to upgrade. If you need help upgrading, consider our upgrade support service. This includes upgrading the core extension and all FishPig add-on extensions. We'll check everything is setup correctly and fix any issues that we find.
To setup automatic post excerpts, you need to make a small modification to the post list default renderer template. This template can be found at the following location:
This is the default template and should not be edited directly. Instead, copy the template and create a copy of it in your custom theme, ensuring the the path stays the same. As an example, if you were using the 'ultimo' package and the 'default' theme, you would copy this file to:
In the file, look for the following code:
<?php echo $post->getPostExcerpt() ?>
This method will first check whether you have explicitly set a post excerpt in the WordPress Admin and if you have, this will be displayed. If you haven't, the method will then check to see whether you have included the More tag. If you have, all content before the More tag will be returned and used as the post excerpt.
We can now make a small change to the code by specifying the maximum number of words we want to use for the post excerpt. If the first 2 checks fail (ie. you haven't specified a manual post excerpt and you haven't used the More tag), the method will take the post content, remove all HTML and limit it to the maximum number of words you specified.
<?php // Display the first 20 words echo $post->getPostExcerpt(20); // Display the first 40 words echo $post->getPostExcerpt(40); // Display the first 100 words echo $post->getPostExcerpt(100); ?>
As you can see, it's really easy to set the maximum number of words for your automatic post excerpts.
We also recommend that you wrap the code in a P tag. The final code should look like this (although you will want to change the number 50 for the actual maximum number of words you want to display).
<p class="post-excerpt"><?php echo $post->getPostExcerpt(50) ?></p>