
I realized that some users didn’t quite understand everything about templates, so I decided to go through all the T2 options and the way the plugin uses Templates. Before asking any T2 related questions you need to read this post first.
Everything plugin renders uses templates. Most of the main templates depend on the other templates. So, when you need to edit something be sure to check if something else is used.
Basics
You CAN’T edit default, pre installed templates, you can only use them to make your own template. And don’t try editing templates in the database directly, because they are saved in serialized state, and any change done directly can cause template to stop working because unserialization will most likely fail. Don’t ask for any help if you did something like that, only thing you can do is to reinstall templates.
On the T2 panel, bellow the list of templates there is a Default Templates button. Most important thing about that panel is that setting default templates there doesn’t mean that everywhere the template is used will use defaults you set there. Default panel and order you set is used only if the you didn’t specify template in some of the functions or shortcodes, or you set the template ID to 0.
HTML/CSS knowledge is preferred for changing templates or making new ones. If you simply need to translate words to your own language this is not important.
ALWAYS give your own templates some meaningful names because you need to be able to identify them later on. All templates you create can be edited later or duplicated for further reuse.
Step by Step
Here is a typical procedure for making your own templates and using them. I will use most common of the ‘big’ templates: Standard Rating Block. This template (SRB) is used to render full rating block for standard post/page template. This template depends on another template:Â Standard Ratings Text. And that one (SRT) depends on the template for word vote(s): Element Word Votes (EWV). Let’s say that you want to translate SRB to a language other than english, and that will require making all 3 templates.
- Duplicated default EWV template. This template has two elements, one for singular and other for plural version of the word votes. Once you are done editing, save the template.
- Now duplicate default SRT template. This one is very complicated, and has 4 elements that are used for different situations. First, normal is most commonly used template. Next two are used in case of the time restricted ratings and they can use more templates than normal element. If you don’t use time restrictions, you don’t need to work on these two. Fourth element is used to display rating message after rating is completed, and the response is returned through AJAX call. Change whatever you want to elements, translate the text or change HTML, but before you save the template, in the Elements list on the right, find %WORD_VOTES% tag, and select template you created in step 1.
- Main template is next. Duplicated default SRB template. There is only one element, and it’s called normal. Notice that if you don’t use some of the tags, you can get rating block without the stars. This template is the one you want to change if you need to change where rating text is displayed: left or right of stars for instance. For most uses you don’t need to change this template, but you need to select tag you created in step 2 for %RATING_TEXT% tag. This will cause that SRB you are editing uses SRT you made and EWV you made.
- Now that you have all templates done, you need to put them to use. Setting them as default using defaults panel is good step if you plan to use functions, and you set template to 0 in the function call.
- To make this new SRB default for rating autoinserted ratings, you need to go to Settings panel. On the Posts & Pages tab you need to set the default rating template. This template will be used for auto inserting ratings. THis is the most important step to make plugin use new template.
That’s all. Same principle is used for all other templates. For instance CRB (Comments Rating Block) uses the same hierarchy as the SRB, so the same rules apply here. Basically these rules apply to all templates. Multi rating templates are the same, except they have more dependencies. New T2 post will be focused on these templates.
If you need to change widgets templates, you also need to set this new template in the widget. So if you had GD Star Rating widget already added to the sidebar using one of preset templates, once you create your own template, go to widgets panel, and edit widget in the sidebar and change template used to the new one.
T2 Map
To get a clearer picture on all the templates, on dependencies between templates you need to use T2 templates map. Map is included with info files that come with the plugin, or you can see (and download) it here.
loading...





Comment Link
Thanks for this post and thanks for the plugins. This cleared up some questions I was having.
loading...
Comment Link
Hey, I begin to get the power of this Plugin.
And while I’m using it, I wanted to expand it, but I don’t know where to begin.
In T2 I wanted to substring the Title… But yeah, it’s not a PHP-Var, so where can I place the Substring? I searched my way through the whole plugin, but I just found /code/t2/templates.php … There are the Functions declared, but yeah, Where is the filter?
Thanks.
loading...
Comment Link
Right now T2 doesn’t uses additional filters for the content so that you can manipulate values before output, but it’s in the plans. Starting from 1.5.6, each version will have few new filters for content.
loading...
Comment Link
Could you give me a hint where to manipulate it? *g* render.php? I tryed to change this
$rt = str_replace(‘%TITLE%’, __($title), $rt);
to this
$rt = str_replace(‘%TITLE%’, __(substr($title, 0, 20)), $rt);
Guess what, it did not work… I got the error unexpeced $end…
loading...
Comment Link
Rendering for all templates is in ‘/code/t2/render.php’. It should work, since I made some similar change for another website.
loading...
Comment Link
Next 1.5.5 will have 3-4 filters for content rendered by the templates.
loading...
Comment Link
One more thing. For widgets, title can be shortened using widget options.
loading...