WordPress.org

Make WordPress Core

Opened 10 months ago

Last modified 10 months ago

#24588 new enhancement

Excerpt enhancement request

Reported by: Looimaster Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:

Description

I originally posted this on WordPress StackExchange but I think that this should go to trac for consideration as well.

I was wondering what should be used in index.php (post listing page): the_excerpt() or the_content()?

  1. Twenty Thirteen uses the_content() but this prints entire content unless <!--more--> exists and it completely ignores Excerpt field from [Posts > Add New > Excerpt].
  2. So, I used the_excerpt() instead but this doesn't react to <!--more--> tag at all and it just grabs first 55 words or uses manual Excerpt and doesn't produce "Read more..." link.

What I think is the most expected behavior is this:

  • print 55 words
  • but react to <--more-->
  • and if manual excerpt is specified, use this instead (most people don't want the beginning of their post to be their excerpt so this is of crucial importance)
  • produce optional "Read more..." link

I know what you say here:

But what I described above looks like the most intuitive to me for post listing pages. The excerpt should be a single, configurable function that is suitable for both BLOG and ARCHIVES. And the_content() can stay for SINGLE.

Currently neither the_content() nor the_excerpt() works for BLOG and requires filters.

the_content() would do the job right but I think that most theme users aren't familiar with <--more--> tag and they rather expect that themes will create proper excerpts for post listing pages rather than displaying full post content (and after all the_content() ignored manual excerpt so it's a big drawback). Currently this can be achieved only with custom filters.

Change History (4)

comment:1 Looimaster10 months ago

Current excerpt function:

the_excerpt();

Improved excerpt function:

the_excerpt( $word_count = 0, $more = true, $manual_excerpt = true );
  • 0 = full post content, 1 or more = number of words to cut after
  • more = should it parse <!--more--> tag? Note: this can be also responsible for choosing ellipsis and/or "Read more..." text like it does it now in the_content()
  • manual_excerpt = should be set to false for backwards compatibility but the excepted would be true

(actually, with such configurability you can even merge the_excerpt() and the_content())

comment:2 knutsp10 months ago

Most themes that use the excerpt on archive pages add their own "Read more"-link, either trough a filter or explicitly in the template. Why is that a problem?

If "theme users" are not aren't familiar with the <!--more--> quicktag, then why would they be familiar with using the manual excerpt?

The word count is filterable. Why also as an argument? One way or the other, and we have a filter.

To me this makes perfectly sense, quoted from the codex:

When a post has no manual excerpt and the post template uses the the_excerpt() template tag, WordPress generates an excerpt automatically by selecting the first 55 words of the post. When the post template uses the the_content() template tag, WordPress will look for the More tag and create a teaser from the content that precedes the More tag.

Through has_excerpt() you can make a choice for each post. You should even be able to detect if the post author has used the <!--more--> tag in the content, or not.

So what is it you cannot do with these template tags and the available filters?

I guess that if there is a very common use case, there could be a the_content_or_excerpt() function, based on some standard criteria, to make life easier for theme developers.

comment:3 Looimaster10 months ago

Well, I'm leaving it up to you. Like I mentioned I can use filters and this works but I think that plugins such as this http://wordpress.org/plugins/advanced-excerpt/ are created because the original function is lacking everything that this plugin does.

the_content_or_excerpt() would probably be a good improvement.

Note: See TracTickets for help on using tickets.