Build Your Own Business Website header image

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.

Lesson 16 – Part 2 – Use a Thesis Filter to Change the Comment Form Title

Difficulty Level -

Listed Under Lesson Subjects -

Use a Thesis Filter to Change the Comment Form Title

Welcome back to Part 2 of Lesson 16 of the Build Your Own E-Commerce Website tutorial series. In this second part of the lesson we are going to modify the comment form title and turn comments into product reviews using a Thesis Filter.

Let’s take a look at this site that we’ve developed for the purpose of demonstrating this, www.estore16.byobtutorial.com. If we come over here and take a look at one of our products and select it, this is the title we want to change. We don’t want it to be Leave a Comment, we want it to be Write a Product Review. So let’s go ahead and open up our custom_functions.php file. I’ve done that here and this is the custom_functions.php file for estore16 and it contains all the functions that we’ve written in the past.

Select the Correct Thesis Filter

The first thing we’re going to do is to copy this block of comment text and paste it. This function is going to replace the default comment form label for product posts. Let’s give ourselves this little space and we’re going to go back to that DIY Themes page and the filter that we’re going to use. Select this Filters button. You can see that there are a whole bunch of different Thesis filters associated with comments. You’ve got comments_closed, comments_intro, comments_link, comments_link_closed, comments_navigation. What we’re going to be working on is comment_form_title, so let’s go ahead and select that.

Write the Filter Function

So this can be used to replace “Leave a Comment” which appears as the title of the comment form. We’re going to copy that – all that text, go back to our custom_functions.php file and paste it. What happens is it will take that block of text and replace all of it with Talk to Me. So we save this file and upload the file using Filezilla. Let’s go to the appropriate site, and then go to themes, thesis_18, custom, then custom_functions.php. Now when we refresh the site, “Leave a Comment” should be changed to “Talk to Me”, and it is.

Okay, it is changed both on our product posts and on our non-product posts. So if we come and take a look at this it says “Talk to Me” on our non-product posts as well. Now we need to do two different things. One of those things is to make it say what we really want it to say and the other one is to make it say that where we want it to say it.

Using a Conditional Statement

So let’s open up NetBeans again. We are going to use a conditional statement and that conditional statement is going to ask the question, if the post is within one of our product categories which are Books and E-Books which is in this case product ID 5 and product ID 6, if it’s in one of those categories then return “Write a Product Review”, and if it isn’t then we want it to return “Leave a Comment”.

Make the Function Conditional for Products Only

We’ll start off by giving ourselves a new line and if and then opening and closing parenthesis. Before we go any further with this, I want to take a look at the conditional tag that we’ll be using. So let’s open up a browser window and search for conditional tags. That brings us to the WordPress Codex and here are all the conditional tags. You’ve seen a lot of these in the past, right? – is_home, is_front_page — that sort of thing.

Scroll down here to about the middle where they have the stuff on categories. We’re not using is_category. We’re not saying if it’s category 5 because this is_category only applies to category archive pages. It does not apply to posts of a specific category. If we want to use posts in a specific category what we need is in_category, so that’s what we’re going to use here. If it’s in_category and since we have more than one category we’re applying it to we’re going to use this form if it’s in_category( array( 1,2,3) ), then it will perform that action.

Copy that code and come back over to NetBeans and paste it inside those parentheses. It’s in_category( array( 1,2,3) ). Of course we’re not using 1, 2  and 3, we’re using 5 and 6 so let’s go ahead and replace that now – 5 comma 6. So if it’s in_category( array( 5, 6) ), then our opening bracket and then our closing bracket. If it’s in category 5 or 6 then we want it to return not “Talk to Me”, but “Write a Product Review”. If it’s not in category 5 or 6 then we’ll say else and give ourselves a space and we will return, “Leave a Comment”.

Add a Filter to the Thesis Comment Form Title

Then down here we’re adding a filter to the thesis_comment_form_title and the function that is affecting that filter is my_comment_form_title.

Let’s save this, upload it and then test it. Come back over to here, refresh, so here we are in a product post, right? – Confessions of a WordPress Trainer, Write a Product Review and now it says 2 Comments … “Read them below or Add one”. This is something else we’re going to change here next.

Go back over to our blog, take a look at this post and it says Leave a Comment. So we succeeded in changing this the way we wanted it changed.

That wraps up Part 2 of Lesson 16 of the Build Your Own E-Commerce Website tutorial series.

Save $200 on Membership Now!

Start learning today for as little as
$0.82 PER DAY!
THIS IS A LIMITED TIME OFFER!
Subscription Options
0 Comments… add one
0 comments… add one

Leave a Comment