WordPress Help Sheet and cheat sheet


Theme Structure
If you want to create a Wordpress theme, these following files must be included in order to be a standard theme. You can create a theme using fewer files but this is the way to do it.
1 header.php - header section
2 index.php - main section
3 sidebar.php - sidebar section
4 footer.php - footer section
5 single.php - post template
6 page.php - page template
7 comments.php - comments template 8 search.php - search content
9 searchform.php - search form
10 archive.php - archive
11 functions.php - special functions 12 404.php - error page
The Loop
You will often see “the loop” as reference in many tutorials or samples. This piece of code helps you display your posts on a blog. By entering custom HTML or PHP code inside the loop, you will make every post to benefit from that custom code. You can use the loop mainly in your index.php file but also in other files when you want to display multiple posts.
1 < ?php if(have_posts()) : ?>
2 < ?php while(have_posts()) : the_post(); ?> 3 // Custom HTML & PHP code
4 < ?php endwhile; ?>
5< ?php else : ?>
6 < ?php endif; ?>
Note: the space in front of ?php on the line 1,2,4,5 and 6 should be removed. So instead of < ?php we will have <?php.
Template Include Tags
These tags are usually used in a single PHP file to include other files from the theme. For example you can use the get_header tag in index.php in order to include the head in the theme.
1 < ?php get_header(); ?>
2 < ?php get_sidebar(); ?>
3 < ?php get_footer(); ?>
4 < ?php comments_template(); ?>
Template Bloginfo Tags
These tags are used to display information regarding your blog, information that can be customized inside the Wordpress Administration panel.
1 < ?php bloginfo('name'); ?> - Title of the blog
2 < ?php bloginfo('charset'); ?> - Displays the character set
3 < ?php bloginfo('description'); ?> - Displays the description of the blog
4 < ?php bloginfo('url'); ?> - Displays the address of the blog
5 < ?php bloginfo('rss2_url'); ?> - Displays the RSS URL
6 < ?php bloginfo('template_url'); ?> - Displays the URL of the template
7 < ?php bloginfo('pingback_url'); ?> - Displays the pingback URL
8 < ?php bloginfo('stylesheet_url'); ?> - Displays the URL for the template's CSS file 9 < ?php bloginfo('wpurl'); ?> - Displays URL for WordPress installation
10 < ?php bloginfo('name'); ?>
Wordpress Conditional Tags
Conditional tags are simple but helpful tags that can be used to customize how your blog will work. For example if the page is the home page, we will type a class called “current-cat”. < ?php if(is_home()) { ?> class=”current-cat”< ?php } ?>. This is a part of the code which I will present you a little bit later in this article.
1 is_home() - when the user is on the home page(blog)
2 is_front_page() - when the user is on the home page (blog or page) 3 is_single - when a single post is displayed
4 is_sticky() - check if a post is sticky
5 is_page() - when a page is displayed
6 is_category() - when a category is displayed

These are the most common conditional tags inside Wordpress. For more information and additional tags you can check the next address dedicated to conditional tags. http://codex.wordpress.org/Conditional_Tags
Common Wordpress Tags
As you know Wordpress has a lot of code that can be embedded in themes in order to make them complex and powerful. Here are some of the common snippets that are used in most of the templates.
1 < ?php the_time() ?> - Displays the time of the current post
2 < ?php the_date() ?> - Displays the date of a post or set of posts
3 < ?php the_title(); ?> - Displays or returns the title of the current post 4 < ?php the_permalink() ?> - Displays the URL for the permalink
5 < ?php the_category() ?> - Displays the category of a post
6 < ?php the_author(); ?> - Displays the author of the post
7 < ?php the_ID(); ?> - Displays the numeric ID of the current post
8 < ?php wp_list_pages(); ?> - Displays all the pages
9 < ?php wp_tag_cloud(); ?> - Displays a tag cloud
10 < ?php wp_list_cats(); ?> - Displays the categories
11 < ?php get_calendar(); ?> - Displays the calendar
12 < ?php wp_get_archives() ?> - Displays a date-based archives list
13 < ?php posts_nav_link(); ?> - Displays Previous page and Next Page links 14 < ?php next_post_link() ?> - Displays Newer Posts link
15 < ?php previous_post_link() ?> - Displays previous link
Wordpress Navigation Menu
This thing is different based on how you want your blog to work. You can have a menu based on pages, on categories or on both. In every way you will need a home page link. In this case here the the 2 approaches for the menu.
2 of 3
3 of 3
the menu.
Categories based menu
1 <ul id="menu">
2 <li <?php if(is_home()) { ?> class="current-cat"< ?php } ?>> 3 <a href="<?php bloginfo('home'); ?>">Home</a></li>
4 < ?php wp_list_categories('title_li=&orderby=id'); ?>
5 </ul>
Pages based menu
1 <ul id="menu">
2 <li <?php if(is_home()) { ?> class="current_page_item"< ?php } ?>>
3 <a href="<?php bloginfo('home'); ?>">home</a></li>
4 < ?php wp_list_pages('sort_column=menu_order&depth=1&title_li='); ?> 5 </ul>
In both cases we add a class that is used by Wordpress in styling the list items. So, in this case we will add the classes to a hardcoded home list item.
Display X posts from a category
On the first page we have in the sidebar 2 sections for latest tips and latest graphic ratings. Those sections were made with the help of the query_posts.
1 < ?php query_posts('category_name=Name Here&showposts=10'); ?>
The name should be exactly the same as the one typed in the Administration panel under categories section.
Custom Template File
In Wordpress you can insert any additional template file that is none of the ones in the first section. In this way you can make your own template file and embed it in your theme.
1 < ?php include (TEMPLATEPATH . '/searchform.php'); ?>
Theme images by fpm. Powered by Blogger.