The Code of Wordpress Widgets

CMS have the advantage of automatically generate links to content, allowing easier and various access to articles. The main examples are the list of recent posts, the list of "related" post, and the tag cloud.
The code of these elements is encapsulated into a PHP function that can be placed anywhere in the interface: in the side panels, at end of the articles, on the homepage, in the footer ...
Knowing these codes allows to customize the theme of his site, or even to create one entirely.

The list of codes


<?php wp_list_categories('show_count=0&title_li=<h2>Categories</h2>'); ?>

The option show_count indicates whether we display the number of posts in each category or not.
We do not add a text after title_li= if the title is defined separately in the template.

Tag cloud

<?php wp_tag_cloud('smallest=8&largest=17&number=30'); ?> 

We see that it is possible to define the size of the smallest and the largest label, and their maximum number.

Recent posts

<?php wp_get_archives('type=postbypost&limit=10'); ?>

Search box

<?php include (TEMPLATEPATH . '/searchform.php'); ?>

The searchform.php file, which is in the directory of the theme, defines the format of the search box. Its content varies depending on the theme.


<?php wp_list_bookmarks('categorize=0&title_li='); ?>


<?php wp_get_archives('type=monthly'); ?>


<?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
<?php wp_meta(); ?>


<a href="<?php bloginfo('rss2_url'); ?>" 
   title="<?php _e('Syndicate this site using RSS'); ?>">
   <?php _e('<abbr title="Really Simple Syndication">RSS</abbr>'); ?>


The list of related articles is not part of the code of Wordpress but comes from plugins, and there are several such plugins.
See the list of best plugins for Wordpress.


The widgets contain similar codes but they are integrated in a drag and drop system. The advantage of widgets is that the webmaster can move the elements of the interface to easily customize the theme.
The disadvantage is that he can only place these widgets in sidebars.

If widgets are chosen, codes above are removed from the template or ignored.


This list of codes does not include interface elements such as author, date, title etc.. All these are parts of the composition of pages and is seen in the context of creating or editing a theme.

See also