Using the_content for excerpt with Roots

What would be the best way to use the_content as excerpt (with no Read more-link) in a template, and make the -function in the editor work?

I know this probably is Wordpress-specific, but I’m kinda lost. In other themes I’ve used the_content( ‘Read more’ ); to do this, but that doesn’t seem to work with Roots.


This is one of the things that got me when I first started using Roots - there is no archive.php file, so when you’re looking at your blog index, it’s falling back to index.php.

Index.php calls from templates/content.php, so if you want to edit the_excerpt (or the_content) you change it there.

It got me a little twisted because the individual single.php template files has the full loop, but the index.php calls content.php. So that’s probably what you need to check to make this work.

Thanks for answering.

Sure - this works when looking at a category index - but the tag works both with the_excerpt and the_content, so thats fine.

I’m doing this in base.php (probably not the best way to do it)):

<?php if ( is_page( 'Home' ) ) { ?> <?php get_template_part('templates/home-categories'); ?> <?php } ?>

In the home-categories.php-template I’m listing the title and featured image of some articles, and I also wan’t to list an excerpt based on the tag in the article.

the_excerpt gives me, as expected, an excerpt based on a number of words.
the_content gives me the whole article, but I’m trying to get only the content before the tag.

I’m repeating myself here, but now you probably see the problem.

I’m a bit confused as what you have and what you’re trying to do. What is home-categories.php? Is that a section on your homepage?

Yes, that’s exactly what it is. A bunch of sections, actually. One section per category.

I’m trying to do what rethles has done with the homepage, kinda.

As @mAAdhaTTah said you need to make your changes to templates/content.php as well as any other content templates you’ve created for post formats e.g. templates/content-video.php. Also, I posted this on the Google Group a while back but you may need to customise the conditions:

  $more_tag = strpos($post->post_content, '<!--more-->');
  (is_home() && $more_tag) ? the_content('Read more') : the_excerpt(); 

If that doesn’t work, it’s probably because you have your front page set to a static page, instead of showing your latests posts. Static pages/single posts will ignore the <!--more--> tag unless you tell them otherwise by setting the global $more variable to 0 within the loop (best check the codex to be sure).

Finally, if you’re trying to replicate the excerpts from the Roots site, it doesn’t use the <!--more--> tag at all. I completely overhauled this better excerpts script to get it how we wanted it.


Thanks Foxaii.

I did try to change content.php without any luck (no difference).

Here’s what I’m trying to do, and how I’m doing it:

I have the front page set to a static page, using a custom template to get rid of the page-header (probably not the best way to do it).

In base.php I’m calling for two different templates, one before the wrap-class, and one after (the reason I’m doing this is for altering the html to make a full-width design, with a similar setup as, to list articles from different categories.

In these two templates I wan’t to use the_content as the_excerpt, and use the tag in the articles to decide how long the excerpt should be / what it should contain (on the front page).

This pointed me in the right direction, but no luck yet (could it be something with the loop?):

Update: I figured it out. Just as the codex says;

//The code must be inserted ahead of the call the_content, but AFTER the_post()

And then it works.

btw, are any roots-themes available in public? It would be nice to see how other people organize their templates.

I’m trying to use the_content() for excerpts in category.php, but it’s not responding to custom link text.

I’m using the following code in templates/content.php (in this case, called from category.php)

  	$more_tag = strpos($post->post_content, '<!--more-->');
  	($more_tag) ? the_content('Continue Reading') : the_excerpt(); 

For posts that have a <!--more--> inserted the above code generates a link like this:

<a class="more-link" href="/topic/article/#more-127850">Read more</a>

As you can see the link text generated is “Read more” instead of “Continue Reading” as I had specified.

What’s particularly confusing is that I can’t find the text “Read more” or even “more-link” defined anywhere in the theme or wordpress codebase.

Does anybody know why this might not be working? Without being able to search for the text that’s actually being used on the generated link, I’m not even sure how to debug this.