Since you’ll be doing a lot of stuffwith the template tags, understanding parameters is crucial. There are three types of template tags, which have been touched on already. The first kind takes no parameters at all, the second takes one or several parameters within quotation marks, while the third type is the one called query style, separating the various options with ampersands. Naturally, not passing a parameter at all means that you just put the template tag wherever you need it, and this also goes for the other template tags since there is a default output. The problems come when you need to change that default output, and hence the parameters. In the preceding examples, you have done all this. Remember, you passed just one piece of information in a parameter to the bloginfo() template tag:
<?php bloginfo('name'); ?>
Then you passed a parameter in PHP function style, with the edit_post_link() template tag. Here, you told the template tag what the link text should be, and what should come before and after it, separating each instruction with a comma and putting the data within quotation marks:
<?php edit_post_link('Edit this post', '<p>Admin: ', '</p>'); ?>
Finally, you passed a lot of options within a query-style parameter to output a tag cloud with wp_tag_cloud(). This method splits parameters with ampersands, and lets you change just the settings you want:
<?php wp_tag_cloud('smallest=10&largest=24unit=px&orderby=count&order=RAND'); ?>
At this point, this section gets a bit technical. There are three ways to pass data to template tags, and although the template tag’s definition (as stated in the WordPress Codex wiki) will tell you exactly how to pass data to that particular template tag, it may be a good idea to know what’s behind it. You can’t just pick one and go with it, you need to find out what the particular tags want. First you’ve got strings, which are lines of text. The bloginfo('name') example is a string, because you tell it that 'name' is the parameter. Strings are found within single or double quotation marks (they do the same thing), although the single version is a lot more common and the one used in the examples in this article.
Integers are whole numbers, such as 55900 or -3 for that matter. You can pass them inside quotation marks if you want, but you don’t need to. They are usually used whenever you need to fetch something that has an ID, which is a lot of things. You’ll stumble onto template tags as well as conditional tags that do this later on.
Finally, there are the boolean parameters, which basically mean that something is either true or false. You can pass this information with all capitals (TRUE or FALSE), all lower case letters (true or false), or using numbers (1 being true and 0 being false). However, you cannot put boolean values within quotation marks; they always stand on their own. For example, the get_calendar() template tag only takes one instruction, and that is whether to display the full day, or just a one-letter abbreviation. True is the default value and displays the first letter in the name of the day (for example, M for Monday), so if you want to output Monday instead of M, you need to set get_calendar() to false:
<?php get_calendar(FALSE); ?>
No quotation marks or anything are required, just plain text. You can also write false in lower case, or just put a 0 in there. Another example of boolean instructions is the_date() template tag, usually used to output the date of a post. You may, for example, want to use that information in PHP instead, and display nothing. Reading up on the template tag reveals that you can change the output format of the date (the first string in the parameter), what goes before the outputted date (the second string), and after it (the third string). The fourth instruction you can pass, however, is a boolean that tells the system whether to output or not (true by default). Say you want to output a year-month-day date (Y-m-d says the PHP manual for date functions; WordPress can take them all) within a paragraph. It would look like this:
<?php the_date('Y-m-d', '<p>', '</p>'); ?>
However, if you want to use this with PHP for some reason, outputting nothing, you can set it to false with the echo option that this template tag has. This goes last, is a boolean value, and hence you won’t put it within quotation marks:
<?php the_date('Y-m-d', '<p>', '</p>', FALSE); ?>
This would give you the same result, being year-month-day within a <p> tag, but it would output nothing so if you want to use it you need to do something funky with PHP. It may be good to remember that strings are text within quotation marks, integers are whole numbers, and Boolean parameters are true or false without any quotation marks. With this in mind, it’ll be a lot easier to understand the template tags you’ll use to build really cool WordPress sites.
Our website is not responsible for the information contained by this article. Webworldarticles.com is a free articles resource thus practically any visitor can submit an article. However if you notice any copyrighted material, please contact us and we will remove the article(s) in discussion right away.
This article was sent to us by:
Benjamin Huffrey at
05152010
1. Creating Your Own Wordpress Template Tags
All articles in this directory are property of their respective authors. Additionally, read our Privacy Policy
© 2010 WebWorldarticles.com - All Rights Reserved.