‘; echo ‘
‘ . $testimonialtext[‘testimonial’]. ‘
‘; echo ‘
‘ . $testimonialtext[‘name’].’
‘; echo ‘
Table of Contents
Having testimonials displayed on your client’s website is a always a nice bonus, and helps to highlight the brand’s personality and keep up with its audience.
The scope of this tutorial is to build a WordPress Testimonial Page Template with the help of WCK – Custom Fields and Post Type Creator plugin.
How you choose to do this is a matter of preference. You can opt for one of these options:
For us, the most flexible and intuitive way to create a WordPress Testimonial Page is by using Custom Fields and create our own Page Template. We’ll use the WCK – Custom Fields Creator to speed things up.
The first step of our tutorial is to create our page, from the Pages menu.
The page will be simply called ‘Testimonials’, and will be later used to display the client’s testimonials.
Next, we need to create our custom page template, in order to customize it with the proper fields.
When choosing the page template, we have to create our own template which will actually show this metabox created by us only on pages that have this particular page template.
So, let’s create a new template by entering our theme folder and create a new .php file called testimonials.php.
For the beginning we will only start with a template name inside a PHP comment, and after that insert the following piece of code for our custom page.
The custom page template we are about to create is based on the TwentyTwelve theme.
First you need to enter a template name and copy the page.php content over to testimonials.php
1 | <!--?php /** * Template Name: Testimonials * Description: A Page Template for displaying Testimonials. */ get_header(); ?--> |
The same logic applies even if you’re using a different theme, the only thing that might differ is the html structure.
Extra information on how to create your own page template can be found here.
The next step would be to download the WordPress Creation Kit plugin, install and activate it.
WCK will help us with the creation of the custom fields that we will attach to the Testimonials page template.
Right after activating the plugin, you’ll notice a new menu item called WCK. It has the following tabs: Start and Settings, Post Type Creator, Taxonomy Creator and Custom Fields Creator.
Now that the page was created we need to add custom fields to it. For this we’ll use WCK – Custom Fields Creator. Click ‘Add new Meta Box’ and let’s start filling out the fields.
Adding a new Meta Box asks primarily to complete the Meta Box Arguments, as shown below. The argument ‘Meta Name’ has to be unique, and further attached to a page. We named it “testimonialsarea”.
For the ‘Repeater’ and ‘Sortable’ argument we will select yes, since we will want to add a variable number of testimonials to our page. From the page template dropdown make sure you select: Testimonials.
Next we can start adding the ‘Meta Box Fields’, which will actually hold our meta data.
For our WordPress Testimonial page we added the Name, Testimonial and Avatar custom fields. For this fields we have to fill in the Field Title, Field Type, Description, and if needed the ‘Required’option. As you’ve seen, when completing the ‘Field Type’ you’ll be able choose from a variety of custom fields: wysiwyg editor, upload, text, textarea, select, checkbox, radio.
Custom Fields are just some extra fields that display arbitrary extra information to a particular post or page. (See more about them here.)
Now, we just have to hit the ‘Publish’ button and go back to our Testimonial Page.
Once on the Testimonials page make sure to select the “Testimonials” page template from the Page Attributes section.
After making this selection and clicking “Update” the Testimonials Box with the defined custom fields will appear beneath the wysiwyg editor box.
Now we can start inserting our data in these fields. Lets add three testimonials, by completing all our custom fields and clicking “Add Entry”.
Hitting the ‘Update’ button will save our information, but as you will see, nothing is displayed on our page in the front-end.
We’ll be able to get our testimonials displayed by adding the code below to our newly created page template. Make sure to include the following part in the testimonials.php file inside the loop.
‘; echo ‘
‘ . $testimonialtext[‘testimonial’]. ‘
‘; echo ‘
‘ . $testimonialtext[‘name’].’
‘; echo ‘
‘; } ?>
As you can see, we have to make use of certain functions for our avatars to get displayed, because the uploads store only the ID, and the function we have to use is wp_get_attachment_image_src.
What’s there left to mention is the extra style of how our testimonials are displayed on our particular page. We will modify a bit our style.css sheet to design the custom fields and that should be pretty much it.
Before saving our final WordPress Testimonial Page, I removed the widgets for this page, for a clearer result, and may do this if you want.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | .tcontainer{ width:239px; float:left; margin-right:20px; margin-bottom:20px; border:1px solid #ccc; border-radius:3px; } .tcontainer p{ font-size:80%; padding:20px; margin:0; } .tcontainer .tcontent{ min-height:280px; } .tcontainer .tname{ font-size:100%; background:#fffce9; font-weight:bold; text-decoration:italic; text-align:center; border-top:1px solid #ccc; } |
This is it, you have created your very own WordPress Testimonial page powered by Custom Fields! This tutorial was meant to give you a better perspective on how WCK may come in handy in different development tasks.
The plugin’s functionality extends way more than what’s shown in this tutorial so if you have a particular project in mind where you think WCK may help make sure to leave a comment.
Adding custom fields to your WordPress site helps you display additional information about your content and can improve SEO for Google and other search engines. But how to show custom fields can be a pretty challenging thing to achieve by non-technical users By default, WordPress gives you the possibility to add custom fields (sometimes called […]
Continue ReadingIf you’re building a user-focused website, creating a WordPress custom reset password page is a no-brainer. Users forgetting the password to their accounts is inevitable, so it only makes sense to offer them a way to recover their password. In this post, you will learn everything there is to know about creating a WordPress reset […]
Continue ReadingDepending on the type of WordPress site you run, there are several reasons why you might want to create a custom login page for WordPress. And, you can easily do so by using a dedicated plugin. Using a customized login form can help you minimize hacking risks and related security issues as well as improve […]
Continue Reading
Hi, nice and useful tutorial. I’m wondering about one thing though, is it possible to set a single testimonial ‘on hold’ or to save it as a draft that can re-enabled later? As opposed to deleting it completely.
It can be done. For example, you could create a drop-down field called Status that can be Published or Draft.
Then, in your template, you query for the status of the testimonial and if it’s a draft you don’t print the result.
Thanks for the reply. Sounds like a good idea. I’ll give it a try. 🙂
Hi, cristian !
Is there any plugin or thing where i can get testimonials from client or people naturally ? (like a commenting system)