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 "".
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('/#more-\d+/i','',$link); } add_filter('the_content_more_link', 'remove_more_jump_link');
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!

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

WebStorm Mac version
Useful JavaScript development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Notepad++7.3.1
Easy-to-use and free code editor
