Build Your Own Business Website header image

Introduction to Customizing Thesis 2.1 Using PHP – Part 14 – Example #7 – Add the Read More Link to the Excerpt

Difficulty Level -

Filed Under Topics - , ,

Listed Under Lesson Subjects -

Applies to -

Whoops, you've found some premium content!

Watch the opening clip of this video to preview it,
the full video is available to paid members.

Now that we’ve added excerpt length to our custom excerpt box, we’re going to add the “Read More” link to the excerpt. We’ll come back over here to our master.php where we wrote this “Read More”. We’ll copy that, come back over to box.php and add this function, public function “read more”. Now, we’re not using this if (is_front_page) stuff obviously and let’s just get rid of byob_excerpt_more.

Add Excerpt More Filter

First we’re just going to return it like normal right? We’ll just return this and then we need to add this excerpt_more filter the same way we added this filter. So we’ll copy that filter, paste it there, grab the name. In the filter excerpt_more, use this excerpt_more, save that and now we’ve got this modification that adds “Read More”.

Yes, I do have to declare this function as public, thank you Thomas. My mistake, I do have to do that when pasting that in. Let’s upload it, go view our site and refresh it. Now we have our “Read More” link here. It’s been added and if we click to it, it takes us over to the right place.

Make the “Read More” Link User Customizable

Now, what we really want to do though is make that customizable and the way we do that is to add another HTML option. So we’re going to just take this HTML option that we’ve created previously and create another one. Except instead of ‘length’ it’ll be ‘mor_text’ ‘type’=> ‘length’, ‘label’=>__(‘Read More text’.

Choose the Width

In this case, we have a variety of width choices. We have width as tiny as just 50px, short’s a 120px, I’m going to choose medium for this and come back over here and say medium Then our tooltip is going to be ‘Enter the text you want displayed in the Read More link after the excerpt’, and then the placeholder will change to ‘Read More’. So that is our new option and then we’re going to use that option down here.

Text Choice

So just like we did with this, we’re going to say $exmore = !empty($this->options[‘more_text’]) then [‘more_text’] else, ‘Read More’. So if they don’t put anything in, we’re going to use ‘Read More’ otherwise, we use the more_text and then instead of this, we’re going to use this variable.

So we’ll delete that and then close that out, add a concatenation symbol, place the variable, concatenation symbol and then close that. Now it’s going to take this option, the ‘more_text’, place it in this variable and then take that variable and place it in this location.

So now we have a customizable value. Save that, upload it and let’s refresh this and then go down to our sidebar and look at the Home Excerpt and we can see we’ve got our value there.

Add Custom Excerpt to the Home Page

Actually, we’re not going to put any value on this one but what we will do is come over here and we’re going to do another one of these on our Home page. And we’re going to take BYOB Custom Excerpt and we’ll call this one Home Loop Excerpt and in that, we’re going to use div on this one.

We’re not going to use the class, we’re going to use 60 for the length of our excerpt and then we’re going to use “Read the Rest of the Post” as our “Read More” text for this. Then we’ll drag this excerpt out of here and then drag this excerpt into the Home Post Loop. Save the template, refresh it and now we’ve got a longer one with “Read the Rest of the Post” and we’ve got our shorter one over here with the “Read More” text.

What we’ve done is essentially given us the ability to have different excerpt lengths in different locations with different “Read More” buttons. It’s available for you to use in any template and have different in every template simply by dragging the box in and setting those options which is I believe a fairly powerful toolset.

0 Comments… add one
0 comments… add one

Leave a Comment