4

I'm 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 would like to achieve 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

This looks like the most intuitive to me for post listing pages. Does something like this exist?

If not, should the_content() be used on post listing pages? 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.

Reference:

  • "but react to <--more-->" - react how? "produce optional "Read more..." link" - optional depending on what? – Rarst Jun 16 '13 at 21:45
  • @Rarst "but react to <--more--> - react how?" - cut it earlier if user specifies this tag at certain end of sentence (to avoid sentences cut in the middle); "produce optional "Read more..." link - optional depending on what?" - entirely on developer's choice - current the_excerpt() doesn't allow "Read more..." as a function parameter and only the_content() does allow that. Developers need this for excerpts as well (well, this can be added separately but why then it became a part of the_content() already but not the_excerpt()). – Paul Jun 16 '13 at 21:54
2

Your requirements slant towards using the_excerpt() with adding read more link by custom code:

  • print 55 words - already this by default and adjustable via excerpt_length filter

  • but react to <!--more--> - this already happens, auto-generated excerpt cannot be longer than teaser (part from start of post to <!--more--> tag)

  • and if manual excerpt is specified, use this instead - already works like this

  • produce optional "Read more..." link this is one thing excerpt doesn't do natively. Can be added via:

    • excerpt_more filter, note it is only used if post was cut
    • get_the_excerpt or the_excerpt to append to any excerpt
    • in template, separately for excerpt template tag call
  • Thanks! This works! But there's one thing I missed: I'd like to also add an ability to parse HTML like the_content() does. So, basically, I would prefer it to be the_content() that uses manual excerpt if specified and auto-cuts the content at 55 words. – Paul Jun 16 '13 at 22:09
  • @Paul not impossible (the_content filter and do whatever you want to it), but you will really be bending it very far to achieve something excerpt does already (and as you can see in my post you referenced - there is plenty of logic going on in there). – Rarst Jun 16 '13 at 22:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.