WordPress Displays the word limit and ellipsis for individual articles when displaying a list of articles on a category catalog page

Source: Internet
Author: User

WordPress will be in the corresponding such list page template, traverse the output of each article information, thumbnails, author, text, title, etc.,

The part of the output concrete body uses such a sentence

<?php the_content (");  ? >

The default by calling this function on the page will completely output the WordPress body

But if we need a page that shows all the articles in a category and doesn't output the body of a single article, it's a common requirement that we let it show a button under it that links to the details page of a separate article.

You can first use the <!--more--> tags, and when you edit each individual article, the Ribbon on the editor has an insert more tag in addition to the usual bold resize font, and actually inserts < in plain text mode !-- More-->

By inserting this tag that will not appear on the page, the body content displayed in the corresponding category's list of articles will not contain the text content after the <!--more-->

Next, let's change the code.

General topics typically use index.php, archive.php, or category.php files to display a list page of this type, and find a template file to display such articles

Replace <?php the_content ()?> with <?php the_excerpt ();?> because WordPress has a method that provides such a direct display of the digest, if not defined Summary

He will intercept the contents of the text part of the display

Common topics are often used in conjunction with conditional statements.

<? PHP     if (Is_category () | | is_archive ()) {         the_excerpt ();     }      Else {         the_content ();     ? >

So you can get rid of it at once. All articles that make such a list of articles display the desired body summary

In addition WordPress v2.9 (currently 2015 is v4.3) can also modify the specific summary display of the word limit, in the use of the theme of the functions.php to add functions

function New_excerpt_length ($length) {     return ; } add_filter ('excerpt_length', 'new_excerpt_length ' );

By default, post-summary content is displayed as "[...]". If not,
Then the same can be added in the functions.php the specified representation of the omitted symbol

function New_excerpt_more ($more) { return '%u2026'; } add_filter ('excerpt_more', 'new_excerpt_more');

WP 2.8 and previous versions of the available code are:

function New_excerpt_more ($excerpt) {     return str_replace ('[...] ' ' ... ' , $EXCERPT); }add_filter ('wp_trim_excerpt'new_excerpt_more ');

WordPress Displays the word limit and ellipsis for individual articles when displaying a list of articles on a category catalog page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.