WordPress development is quite interesting as WordPress provides a highly interactive and friendly user interface that does not only helps experts but beginners as well. Behind a fabulous and animated WordPress theme is a complex structure, making your life easier. Most WordPress themes will use the same theme template and file structure. But it is hard to remember all the file names, PHP tags and even the layout you use to define a new theme.
WordPress Cheat Sheet
There are many codes to memorize just to modify a theme, so it is helpful to have a super cheat sheet if you are looking for minor changes within a theme or even developing your own theme. In this article, I will be covering all the files and function that you need to know when modifying or developing themes. This WordPress super cheat sheet is a must-have for expert level theme designers who have to deliver quick theme modification and creation tasks. I am sure this will save their development time.
Basic Theme files
Here is a list of basic theme files every WordPress theme has:
Style.css – Stylesheet file
Index.php – Main body template of the theme from where your theme operates. It uses template tags to bring in all the information from other theme files.
Headper.php – All the header information is kept inside this PHP file. Meta Data and link to external style sheets exists in this file.
Sidebar.php – As the name suggests, all the information regarding sidebars is contained in this file. Widgets, categories, ad blocks, search forms and more.
Footer.php – Copyrights, Company Information, Widgets, Social Links and important page links are present in this file.
Comments.php – This file is responsible for displaying comments on your web posts and pages.
404.php – This PHP file is responsible for displaying an error message once a user visits a page that does not exists on your website.
Functions.php – Here you can write your own custom functions. But it is always recommended to create a child theme instead of editing this file directly.
Archive.php – This file displays an archive on your website and read all of the previous posts as well.
Search.php – This helps visitors to search your site.
Single.php – This files forces to show one post only.
Page.php – You can create a page on your website with this template.
tag.php – This file shows tags in archive form.
category.php – This file shows categories in archive form.
Defining A New Theme
Stylesheet file does not contain styling information only but also details about the theme as well. This information is displayed in the Appearance > Themes section of your WordPress admin panel.
This is a screenshot of stylesheet.css file for the default Twenty Sixteen theme. You can see complete theme information about the theme is written in this file.
Header Tags in Header.php
You can see most of these tags in header.php file. Codes like ”Location of Site’s Theme File” are used to call for image URL’s all over the template and same goes for Exact URL or the site as well. But most of this code is found in header.php.
<?php bloginfo(‘name’); ?> – Title of your website.
<?php wp_title(); ?> – Title of a Specific Page.
<?php bloginfo(‘url’); ?> – Exact URL for your website.
<?php bloginfo(‘description’); ?> – Displays tagline of your blog as set in Settings > General.
<?php bloginfo(‘template_url’); ?> – Your site’s Theme file location.
<?php bloginfo(‘stylesheet_url’); ?> – Your site’s stylesheet file location.
<?php bloginfo(‘rss2_url’); ?> – RSS Feed URL for the Site.
<?php bloginfo(‘pingback_url’); ?> – Pingback URL of your website.
<?php bloginfo(‘version’); ?> – WordPress Version Number installed on your website.
Main Template Include Tags
These tags are used in one template file to call all the website content functions. Mostly it is called in index.php file. PHP has its own built-in include() statement to achieve this, but following WordPress-specific tags helps you do this in a better way:
<?php get_header(); ?> – Includes the header.php file
<?php get_sidebar(); ?> – Includes the sidebar.php file
<?php get_footer(); ?> – Includes the footer.php file
<?php comments_template(); ?> – Includes your comments
More Template Tags
Following tags can be used anywhere in the template files such as index.php or footer.php:
<?php the_content(); ?> – Displays the content of a post
<?php the_title(); ?> – Title of the specific post
<?php the_permalink() ?> – Link of a specific post
<?php the_category(‘, ‘) ?> – Category of a specific post
<?php wp_list_pages(); ?> – Lists all pages
<?php wp_list_cats(); ?> – Lists all categories
<?php the_author(); ?> – Author of a specific post
<?php the_ID(); ?> – ID of a specific post
<?php next_post_link(‘ %link ‘) ?> – URL of the next page
These are some of the important template tags I choose for our WordPress Super Cheat Sheet. For complete list you can visit WordPress Codex page.
The Loop
It is the default mechanism in WordPress for displaying all of your blog posts. You can read more about The Loop here. You can change the number of posts that should be retrieved to display in Settings > Reading menu in The WordPress admin panel.
Usage Of The Loop
Loop can help you achieve:
- Display post titles and excerpts on your homepage.
- Display the content and comments on a single post.
In the above example, the loop says that when there are posts, loop through them and display the content of these posts.
What The Loop Can Display?
The Loop can display a lot of elements for each post. Some of them are:
the_title() – Title of the post or page
the_ID() –ID for the post or page
the_category() – Categories of a specific post or page being viewed
the_excerpt() – read more link or first 55 words of a post’s main content followed by an ellipsis.
the_author() – the author of the post or page
the_tags() – tags associated with a post.
Conditional Tags
is_home() – Returns TRUE if the current page is the homepage
is_admin() – Returns TRUE if an administrator is logged in and visiting the site
is_tag() – Returns TRUE if a page or post has the specified tag
is_404() – Returns TRUE if the current page does not exist
You can find a complete list of these tags here.
Conclusion
WordPress has lots of powers under the hood and you can explore these powers by custom designing your own themes according to your requirements. This cheat sheet can help you a lot by not only providing concrete information in one post but also saving time while editing themes. This above list can be a great resource for you when you are editing themes and creating your own. I have shared the most common tags used in this list and added the link for more as well.