Home >Backend Development >PHP Tutorial >How to display article summary in WordPress

How to display article summary in WordPress

不言
不言Original
2018-07-09 09:41:092828browse

This article mainly introduces the method of displaying article abstracts in WordPress. It has certain reference value. Now I share it with you. Friends in need can refer to it.

Another bad place in WordPress, the home page , categories and other archive pages, articles are arranged in full-text output by default. I don’t know if this display method is popular among foreign blogs now, but I personally don’t like it. If the article is longer and contains a lot of pictures, not only will the page open slowly, but it will also be difficult to quickly find the content you are interested in. According to most domestic users

, here are four ways to display article summaries in WordPress:

1. Use the built-in summary function of WordPress

I currently have another The WordPress blog uses this method, and the display effect is very satisfactory. The only drawback is that the summary needs to be set separately when writing articles. However, this point must be viewed dialectically. Although it is a bit troublesome, it has good flexibility.

Usage setting method:

1. Click "Show Options" in the upper right corner of the article editing page, check the "Abstract" option inside, and write the summary content separately when writing articles in the future. Can.

2. After the article is published, you may see that the full text is still output on the home page, while the summary is displayed on the archive pages such as categories and tags. We can use the following methods to solve the problem.

3. In the WordPress backend "Appearance" - "Edit", click to modify the loop.php file, about line 137, find and modify the following sentence, add a home page applicable judgment, the red font is Add section.

<?php if ( is_archive() || is_search() || is_home() ) : // Only display excerpts for archives and search. ?>

4. After setting, the home page will be displayed in summary like other archive pages.

2. Insert the “more” delimiter tag

1. This is also one of WordPress’s built-in summary methods. You only need to add it when editing the article. After intercepting the summary text, insert the "more" separation tag, click the "more" separation icon in the editor above, or you can directly write the label statement "fc430c7db1eecf4621f4fc8a5479f894".

2. After setting, the homepage and other archive pages will be displayed like a summary, and a "Continue Reading →" link will be automatically added after the summary. However, if you look closely at this link, you may find that #more-id is added at the end. It is a content jump anchor link. Clicking it will go to the summary content to continue reading.

3. Whether to remove this anchor point jump depends on personal preference. If you want to remove it, in the WordPress backend "Appearance" - "Edit", click to modify the functions.php file, copy and add the following code. The meaning of the code is to use the filter of WordPress the_content_more_link, and use it with a regular expression to replace the string in the form of #more-id in the link with nothing.

The code is as follows:

function remove_more_jump_link($link) {
return preg_replace(&#39;/#more-\d+/i&#39;,&#39;&#39;,$link);
}
add_filter(&#39;the_content_more_link&#39;, &#39;remove_more_jump_link&#39;);

3. Modify the theme index.php file

1. Open the folder where you are using the theme and find index. php file, find the following code:

<?php the_content(__(’(more…)’)); ?>或者<?php the_content(); ?>

2. Modify it to:

The code is as follows:

<?php if(!is_single()) {
the_excerpt();
} else {
the_content(__(’(more…)’));//或者<?php the_content(); ?>
} ?>

3. After saving, the article can automatically intercept the summary, but there are disadvantages The formatting in the summary will disappear, such as bold text, font color, etc.

4. Use summary plug-ins

Although there are some aspects of WordPress that are not suitable for our use, fortunately, there are many plug-ins, and there are many plug-ins that automatically set article abstracts, as follows Introducing some of the more useful ones.
1. WP-UTF8-Excerpt: supports multi-byte languages ​​(such as Chinese), will not produce garbled characters and retains the format.
2. WP-Posts Auto Cutter: Use UTF-8 method to intercept, no Chinese garbled characters and retain the summary format. The author of this plug-in has not submitted it to WordPress. You can only download it from the author's homepage: http://blog.netdll.com/?p=1276 (the website is blocked).
3. Limit Posts Automatically: Mainly used for English sites, and errors will occur when using Chinese.

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Wordpress's "Article RSS", "Comments RSS", "WordPress.org" deletion RSS function

The above is the detailed content of How to display article summary in WordPress. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn