WordPress Cheat sheet

WordPress Cheat sheet

This WordPress Cheat Sheet should be enough to get you started developing or tweaking WordPress themes.

Basic Template Files
style.css Style sheet file
index.php Home Page file
single.php Single post page file
archive.php Archive or Category file
searchform.php Search form file
search.php Search content file
404.php Error page file
comments.php Comments template file
footer.php Footer content file
header.php Header content file
sidebar.php Sidebar content file
page.php Single page file
PHP Snippets for Header
bloginfo(‘name’); Title of the site
wp_title(); Title of the specific post or page
get_stylesheet_directory_uri(); The style.css file’s location
bloginfo(‘pingback_url’); Pingback URL for this site
bloginfo(‘template_url’); Location for the site’s theme files
bloginfo(‘version’); WordPress version for the site
bloginfo(‘atom_url’); Atom URL for the site
bloginfo(‘rss2_url’); RSS2 URL for the site
get_site_url(); Exact URL for the site
bloginfo(‘name’); Name of the site
bloginfo(‘html_type’); HTML version of the site
bloginfo(‘charset’); Charset parameter of the site
PHP Snippets for Templates
the_content(); Content of the posts
if(have_posts()): Check if there are posts
while(have_posts()): the_post(); Shows posts if posts are available
endwhile; Closes the ‘while’ PHP function
endif; Closes the ‘if’ PHP function
get_header(); Header.php file’s content
get_sidebar(); Sidebar.php file’s content
get_footer(); Footer.php file’s content
the_time(‘m-d-y’); The date in ’08-18-07′ format
comments_popup_link(); Link for the comments on the post
the_title()’; Title of a specific post or page
the_permalink(); URL of a specific post or page
the_category(); Categor of a specific post or page
the_author(); Author of a specific post or page
the_ID(); ID of a specific post or page
edit_post_link(); Link to edit a specific post or page
get_links_list(); Links from the blogroll
comments_template(); Comment PHP file’s content
wp_list_pages(); List of pages of the site
wp_list_cats(); List of categories for the site
next_post_link(‘%link’); URL to the next post
previoust_post_link(‘%link’); URL to the previoust post
get_calendar()’ The built-in calendar
wp_get_archives(); List of archives for the site
posts_nav_link(); Next and previous post links
bloginfo(‘description’); Site’s description
Navigation menu
Category Based Navigation
<ul id=”menu”>
<li <?php if(is_home()) { ?> class=”current-cat” <?php } ?> >
<a href=”<php bloginfo(‘home’); ?>”>Home</a></li>
<?php wp_list_categories(‘title_li=&orderby=id’); ?>
Pages based Navigation
<ul id=”menu”>
<li <?php if(is_home()) { ?> class=”current_page_item” <?php } >>>
<a href=”<php bloginfo(‘home’); ?>”>Home</a></li>
<?php wp_list_pages(‘sort_column=menu_order&depth=1&title_li=’); ?>
Extra stuff
/%postname%/ Custom permalinks
include(TEMPATEPATH . ‘/x’); Include any file
the_search_query(); Value for search form
_e(‘Message’); Prints out message
wp_register(); Displays the register link
wp_loginout(); Displas the login/logout link
<!–next page–> Divides the content into pages
<!–more–> Cuts off the content and adds a read more link
wp_meta(); Meta for administrators
timer_stop(1); Time to load the page
echo get_num_queries(); Queries to load the page
The Loop
<php if(have_posts()): ?>
<php while(have_posts()): the_post(); ?>
// Post content here (Custom HTML & PHP code)
<php else; ?>
<php endif; ?>
The Loop
    <php if(have_posts()): ?>
         <php while(have_posts()): the_post(); ?>
    // Post content here (Custom HTML     & PHP code)
      <php else; ?> 
    <php endif; ?>


Extend User Contact Fieds in WordPress

Extend User Contact Fieds in WordPress

We can add lots of contact information, depending upon your needs. To extend user contact info, open the files and add in this code

function my_new_contactmethods( $contactmethods ) {
    // Add Twitter
    $contactmethods['twitter'] = 'Twitter';
    //add Facebook
    $contactmethods['facebook'] = 'Facebook';
    return $contactmethods;


This is only a basic example and you can make it more complicated depending on your creative needs
How to Display any External RSS Feed on Your WordPress Site

How to Display any External RSS Feed on Your WordPress Site

Do you know how bloggers who display their other blog’s feed on their site. You want to do it too for extra promotion and traffic. Well here is the tutorial for you. Simply paste the following code in anywhere in your theme:

<?php include_once(ABSPATH.WPINC.'/feed.php');
$rss = fetch_feed('http://feeds.feedburner.com/wpbeginner');
$maxitems = $rss->get_item_quantity(5);
$rss_items = $rss->get_items(0, $maxitems);
<?php if ($maxitems == 0) echo '<li>No items.</li>';
// Loop through each feed item and display each item as a hyperlink.
foreach ( $rss_items as $item ) : ?>
<a href='<?php echo $item->get_permalink(); ?>'
title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'>
<?php echo $item->get_title(); ?></a>
<?php endforeach; ?>



Taxonomy filter for admin area

Taxonomy filter for admin area

While working on custom post everybody struggles while sorting the posts by custom taxonomy,

if you add a code for each taxonomy then it will be lengthy. so here is the code for  sort by all taxonomies.

Add it on your functions.php then sorting will be available on all posts screen of your custom post type.


add_action( 'restrict_manage_posts', 'my_restrict_manage_posts' );

function my_restrict_manage_posts() {
    global $typenow, $post, $post_id;

	if( $typenow != "page" && $typenow != "post" ){
		//get post type
		//get taxonomy associated with current post type
		$taxonomies = get_object_taxonomies($post_type);
		//in next loop add filter for tax
		if ($taxonomies) {
			foreach ($taxonomies as $tax_slug) {
				$tax_obj = get_taxonomy($tax_slug);
				$tax_name = $tax_obj->labels->name;
				$terms = get_terms($tax_slug);
				echo "<select name='$tax_slug' id='$tax_slug' class='postform'>";
				echo "<option value=''>Show All $tax_name</option>";
				foreach ($terms as $term) { 
					$label = (isset($_GET[$tax_slug])) ? $_GET[$tax_slug] : ''; // Fix
					echo '<option value='. $term->slug, $label == $term->slug ? ' selected="selected"' : '','>' . $term->name .' (' . $term->count .')</option>';
				echo "</select>";


Creating custom Post Type In WordPress

Creating custom Post Type In WordPress

WordPress big advantage while comparing with other CMS is Custom Post type mechanism.
Custom post type allows to create large variety of content.
Lets have a look at how to create a custom post type
Custom post types are available from WordPress 2.9.
Custom post type is nothing more than a regular post.
You could create custom post types for books, movies, reviews, Books and so on.

Creating custom post type

To create custom Post type we have a plenty of plugins but we can achieve this by simple script.
Lets create a custom post type for books.
Below is the script for creating custom post type.

function Books() {
$labels = array(
'name' => _x( 'Books', 'post type general name' ),
'singular_name' => _x( 'Book', 'post type singular name' ),

'add_new' => _x( 'Add New', 'book' ),

'add_new_item' => __( 'Add New Book' ),

'edit_item' => __( 'Edit Book' ),

'new_item' => __( 'New Book' ),

'all_items' => __( 'All Books' ),

'view_item' => __( 'View Book' ),

'search_items' => __( 'Search Books' ),

'not_found' => __( 'No Books found' ),

'not_found_in_trash' => __( 'No Books found in the Trash' ),

'parent_item_colon' => '',

'menu_name' => 'Books'


$args = array(

'labels' => $labels,

'description' => 'Holds our Books and Book specific data',

'public' => true,

'menu_position' => 5,

'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),

'has_archive' => true,


register_post_type( 'Book', $args );


add_action( 'init', 'Books' );

Now lets’s discuss about the parameters
Label Option is an array for different labels for our custom post type

A small explanation about the custom Post type.


All to do with Visibiity


To define the position of the custom post type in admin menu.


to get default WordPress controls in edit sections


To create the URL rewrite


Correcting wp-admin 404 error for wordpress under IIS

Correcting wp-admin 404 error for wordpress under IIS

If your server is on IIS  and   running WordPress and experiencing an issue where navigating to /wp-admin results in either a blank page or a 404 error, you may need an additional rule in your .htaccess file. Generally you’ll find that, assuming you’re set up properly, you can reach the admin section by appending /index.php to the URL, but who wants to do that every time?

The rule necessary tells the standard permalink rules to ignore the wp-admin directory when performing rewrites. Simply add the following condition to your .htaccess file:

Here is the .htacess file just upload it into wordpress root folder
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_URI} !^/(wp-admin|wp-admin/.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress