在 WordPress 博客主页上显示摘录: (Show the excerpt on the homepage of WordPress blog: )这篇文章将严格针对第一次想要 在 WordPress 博客主页上显示摘录( show the excerpt on the homepage of WordPress blog)而不是显示全部内容的用户。
大多数主题都可以选择只显示主页上的内容,但您一定偶然发现了那些不显示的主题。在主页上仅显示内容的摘录也是有益的,因为它减少了页面加载时间,最终使访问者感到高兴。
因此,这对每个人来说都是双赢的,不浪费任何时间,让我们看看节目摘录。
在WordPress(WordPress)博客的主页上显示摘录
在WordPress(WordPress)的主页上显示摘录有两种方法,让我们一一讨论。
方法一:使用WordPress插件
我相信WordPress插件让我们的生活变得更简单,一切都可以在WordPress插件的帮助下完成。希望这是这种情况,因为我们将学习如何 使用插件在 WordPress 博客的主页上(excerpt on the homepage of WordPress blog)显示(the)摘录。(show) 这是你要做的:
1.转到您的WordPress 管理员并导航到插件>添加新的。
2.在插件搜索中,输入“ Advanced Excerpt ”,这将自动调出插件。
3.只需安装插件并激活它。
4.这是插件WordPress页面的直接链接。(direct link to the plugin WordPress page.)
5.成功安装插件后,进入高级摘录(Advanced Excerpt)设置(设置>摘录)。
6.在这里您可以根据需要更改摘录长度和许多其他设置,不要打扰,因为您只需要更改摘录长度,勾选“添加阅读更多链接到摘录(Add read more link to excerpt)”,您可以自定义“禁用(Disable On)”。
7.最后,点击保存按钮,一切顺利。
方法二:手动添加摘录代码
大多数用户肯定会使用上述方法,但如果由于某种原因您不想安装另一个插件来完成您的工作,那么欢迎您自己手动完成。
只需打开您的 index.php、category.php 和 archive.php 文件,因为您想在这些页面上显示摘录。找到以下代码行:
<?php the_content(); ?>
用这个替换它:
<?php the_excerpt(); ?>
其余的将由WordPress自动处理。但是问题来了,如何更改字数限制?好吧(Well),您必须更改另一行代码。
从外观(Appearance)转到编辑器(Editor),然后打开 function.php 文件并添加以下代码行:
// Changing excerpt length
function new_excerpt_length($length) {
return 80;
}
add_filter('excerpt_length', 'new_excerpt_length');
// Changing excerpt more
function new_excerpt_more($more) {
return '...';
}
add_filter('excerpt_more', 'new_excerpt_more');
只需更改返回后的值即可根据需要进行调整。
在某些情况下,WordPress不会自动在摘录下方提供指向完整帖子的链接,在这种情况下,您需要再次将以下代码行添加到您的 function.php 文件中:
function new_excerpt_more( $more ) {
return ' <a class="read-more" href="'. get_permalink( get_the_ID() ) . '">' . __('Read More', 'your-text-domain') . '</a>';
}
add_filter( 'excerpt_more', 'new_excerpt_more' );
就是这样,您现在可以轻松地在 WordPress 博客的主页上显示摘录(show the excerpt on the homepage of WordPress blog)。您可以选择使用哪种方法,但正如您所见,第二种方法并不容易,所以更喜欢第一种。
如果您对本指南仍有疑问,请随时在评论部分询问他们,其余的我会处理。
您还有其他方法可以将摘录添加到WordPress博客吗?我很想听听他们的消息。
Show the excerpt on the homepage of WordPress blog
Show the excerpt on the homepage of WordPress blog: This is post is going to be strictly for the first time users who want to show the excerpt on the homepage of WordPress blog rather than showing whole content.
Most of the themes have the option of showing only except of the content on homepage but you must have stumbled upon the ones who do not. Well showing only the excerpt of content on the homepage is also beneficial because its reduces the page load time which ultimately makes visitor happy.
Therefore, it’s a win-win situation for everyone and without wasting any time let’s see how show excerpts.
Show the excerpt on the homepage of WordPress blog
There two methods to show the excerpt on the home page of WordPress lets just discuss them one by one.
Method 1: Using WordPress Plugin
I believe WordPress plugins have made our life simpler and everything can be done with the help of WordPress plugins. Hopefully, this is the case here as we are going to learn how to show the excerpt on the homepage of WordPress blog using a plugin. Here is what you do:
1.Go to your WordPress admin and navigate to Plugins>Add New.
2.In the Plugin search, type “Advanced Excerpt” and this will automatically bring up the plugin.
3.Just install the plugin and activate it.
4.Here is the direct link to the plugin WordPress page.
5.After successfully installing the plugin, go the Advanced Excerpt settings(Settings>Excerpt).
6.Here you can change the excerpt length to your needs and many other settings, well don’t bother as you just need to change excerpt length, tick “Add read more link to excerpt” and you can customize “Disable On.”
7.Finally, hit the save button and you are good to go.
Method 2: Manually adding the excerpt code
Most of the users will definitely use the above method but if for some reason you don’t want to install another plugin to do your job then you are welcome to manually do it yourself.
Just open your index.php, category.php and archive.php file as you want to show excerpts on these pages. Find the following line of code:
<?php the_content(); ?>
Replace it with this:
<?php the_excerpt(); ?>
And rest will be taken care by WordPress automatically. But here comes the problem how do you change the word limits? Well for that you have to change another line of code.
From Appearance go to Editor then open function.php file and add the following line of code:
// Changing excerpt length
function new_excerpt_length($length) {
return 80;
}
add_filter('excerpt_length', 'new_excerpt_length');
// Changing excerpt more
function new_excerpt_more($more) {
return '...';
}
add_filter('excerpt_more', 'new_excerpt_more');
Just change the value after return to adjust it according to your needs.
In some cases, WordPress does not automatically provide the link to the full post beneath the excerpt and in that case, you need to again add the following line of code to your function.php file:
function new_excerpt_more( $more ) {
return ' <a class="read-more" href="'. get_permalink( get_the_ID() ) . '">' . __('Read More', 'your-text-domain') . '</a>';
}
add_filter( 'excerpt_more', 'new_excerpt_more' );
That’s it now you can easily show the excerpt on the homepage of WordPress blog. And you can choose which method to use but as you can see the second method is not exactly easy so prefer the first one.
If you still have a question regarding this guide then feel free to ask them in the comment section and I will take care of the rest.
Do you have any other ways to add the excerpt to the WordPress blog? I would love to hear about them.