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

How to display article summary in WordPress

Jul 09, 2018 am 09:41 AM
wordpress

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. ?>
Copy after login

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 "".

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;);
Copy after login

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(); ?>
Copy after login

2. Modify it to:

The code is as follows:

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

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1253
24
How to adjust the wordpress article list How to adjust the wordpress article list Apr 20, 2025 am 10:48 AM

There are four ways to adjust the WordPress article list: use theme options, use plugins (such as Post Types Order, WP Post List, Boxy Stuff), use code (add settings in the functions.php file), or modify the WordPress database directly.

How to build a website for wordpress host How to build a website for wordpress host Apr 20, 2025 am 11:12 AM

To build a website using WordPress hosting, you need to: select a reliable hosting provider. Buy a domain name. Set up a WordPress hosting account. Select a topic. Add pages and articles. Install the plug-in. Customize your website. Publish your website.

How to change the head image of the wordpress theme How to change the head image of the wordpress theme Apr 20, 2025 am 10:00 AM

A step-by-step guide to replacing a header image of WordPress: Log in to the WordPress dashboard and navigate to Appearance &gt;Theme. Select the topic you want to edit and click Customize. Open the Theme Options panel and look for the Site Header or Header Image options. Click the Select Image button and upload a new head image. Crop the image and click Save and Crop. Click the Save and Publish button to update the changes.

How to import the source code of wordpress How to import the source code of wordpress Apr 20, 2025 am 11:24 AM

Importing WordPress source code requires the following steps: Create a sub-theme for theme modification. Import the source code and overwrite the files in the sub-topic. Activate the sub-theme to make it effective. Test the changes to make sure everything works.

How to view the front-end of WordPress How to view the front-end of WordPress Apr 20, 2025 am 10:30 AM

You can view the WordPress front-end by logging into the dashboard and switching to the View Sites tab; automate the viewing process with a headless browser; installing the WordPress plugin to preview the front-end within the dashboard; viewing the front-end via a local URL (if WordPress is set locally).

What are the plugins for wordpress blocking ip What are the plugins for wordpress blocking ip Apr 20, 2025 am 08:27 AM

WordPress IP blocking plugin selection is crucial. The following types can be considered: based on .htaccess: efficient, but complex operation; database operation: flexible, but low efficiency; firewall: high security performance, but complex configuration; self-written: highest control, but requires more technical level.

How to cancel the editing date of wordpress How to cancel the editing date of wordpress Apr 20, 2025 am 10:54 AM

WordPress editing dates can be canceled in three ways: 1. Install the Enable Post Date Disable plug-in; 2. Add code in the functions.php file; 3. Manually edit the post_modified column in the wp_posts table.

How to register a wordpress account How to register a wordpress account Apr 20, 2025 am 11:45 AM

To create an account on WordPress, simply visit its website, select the registration option, fill in the registration form, and verify your email address. Other ways to register include using a Google account or Apple ID. The benefits of signing up include creating a website, gaining features, joining the community, and gaining support.

See all articles