My Wordpress Cheat Sheet


I know that there are many resources regarding this topic but there are never enough. I have been working a lot with Wordpress lately and am slowly putting together a library of template files that I can just drag and drop into new themes that I put together. I thought I would share just a few of these today. This post is dedicated to small snippets from Wordpress that will make your life easier. Or maybe my life easier and in this case I want to have them in one single post.

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.

themestructure

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.

theloop
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.

templateincludetags

Template Bloginfo Tags

These tags are used to display information regarding your blog, information that can be customized inside the Wordpress Administration panel.

bloginfo

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.

conditional

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.

commontags

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.

Categories based menu

categoriesbasedmenu

Pages based menu

pagesbasedmenu

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.

displaypostsfromcategory

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.

customtemplatefile



Final words

This is my Wordpress Cheat Sheet. For more information, you can search the Wordpress Codex. You can find there all the information you need: tags, parameters, functions, hacks etc. Hopefully this page will help you and it will give you a little more time in designing instead of researching.

Here are some additional Wordpress Code Snippet resources:



  1. No comments yet.
(will not be published)