Provide zblog template_zblog them_wordpress template download and customization

How does zblog intercept a summary with a specified number of words? Introduction to the custom interception method of zblog summary

Tianxing Studio 2024-02-29 19:43 Zblogphp Tutorial four thousand nine hundred and fifty-five 0 Comments


How does zblog intercept a summary with a specified number of words? This article introduces the method of custom interception of zblog summary.

Zblog has a built-in function "SubStrUTF8" to intercept strings. The function is used as follows:

 SubStrUTF8 ('string ',' 20 '); //The function has two parameters. The first parameter is the string to be intercepted, and the second parameter is the number of characters to be intercepted

In the zblog template file, you can use:

 SubStrUTF8($article->Intro,'20');

The above "$article ->Intro" is the article summary, and other callable fields of the article are as follows:

 22.png

PS: In the above method, you may encounter html code or spaces or other non text content in the article summary, resulting in output dislocation. Therefore, you need to filter the string first and then remove the spaces, so the final code is as follows:

 preg_replace('/[\r\n\s]+/', '', trim(SubStrUTF8(TransferHTML($article->Intro, '[nohtml]'),20)));

The "TransferHTML" function in the above code is used to filter the html code, and the "preg_replace" function is used to remove spaces by regular matching. Finally, the specified number of article summaries and article contents can be output perfectly.


Can't find a tutorial that can solve your problem?

You can try to search or ask questions directly online. We also provide charging technical support. If you need it, you can contact us online.

Online questions Online Service

welcome you Comment: Cancel Reply

 Please fill in the verification code
  • Latest articles
  • Hot article ranking
  • Most Comments
Label aggregation