Build Your Own Business Website header image

Introduction to Customizing Thesis 2.1 Using PHP – Part 7 – Example #2 – Add a 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 you know how to change the number of words displayed by an excerpt, next up what we’re going to do is add a “read more” link to the excerpt instead of that little dot, dot, dot.

excerpt_more Filter

Again, we’re going to find that here in this the_excerpt page and the filter for that is excerpt_more. Actually, what we’re going to do is come down here and look at their little example, the add the “read more” link to the post.

Add the Filter to the Function

So function new_excerpt_more. I’m going to copy this and come back over to our master.php and change this to byob_excerpt_more and then change the name so add_filter( ‘excerpt_more’, ‘byob_exceerpt_more’ ).

The excerpt_more filter brings this little more parameter into and you could return more plus this. But what’s happening is, it is replacing that […] with a class=”read-more” href= ” . get_permalink( get_the_ID ) that’s the post id and then the link test “Read More”, okay?

Upload and View the Site

So if we hit save to that and upload it and then look at our example, now what’s happened here is “Read More” has been added to the excerpt and it has been added to all the excerpts, not just on the main page. It’s on every single instance of the excerpt, “Read More” has been added.

Variations for the Read More Link Display

So if you want to play around with it at this point, you could decide that you’re going to put a “return” there first and upload it and refresh it and now, the “Read More” link drops down to a new line.

However, if you want it to be different here than it is here, again that’s a very difficult thing for you to target. But we could again, take this if(is_front_page) and say if it’s the front page, return that and otherwise, return $more. So now, it’s only going to show this “Read More” on the front page but it won’t show it elsewhere.

Maybe what we do instead of that is just make it a different text so “Read More Stuff”, right? So on the front page we’ll get the “Read More” and on every other page we’ll get “Read More Stuff”.

Again, it’s a way of using conditional language to determine what should happen where and it may seem pretty simplistic, here it says “Read More Stuff”, “Read More Stuff” but you come over to the front page and it’s just going to say “Read More”.

This may seem simplistic but the purpose of me showing you something that is this simplistic is to be able to show you the benefit of using a box. Because the box is not going to require that kind of convoluted set up.

When we’re done with this process, our box is going to be able to change the excerpt length every time you insert a new excerpt like that and change the “Read More” text every time you insert “Read More” so we’re going to make this quite a bit more customizable in that new system.

0 Comments… add one
0 comments… add one

Leave a Comment