Inside WordPress templates   PDF Print E-mail

For those of you who are developing WordPress templates or you just want to modify existing ones, the following commands sheet should be helpful.

Theme Structure

  • header.php - Header Section
  • index.php - Main Section
  • sidebar.php - Sidebar Section
  • single.php - Post Template
  • page.php - Page Template
  • comments.php - Comment Template
  • search.php - Search Content
  • searchform.php - Search Form Template
  • archive.php - Archive Template
  • functions.php - Special Functions
  • 404.php - Error Page template
  • style.css - Style Sheet

 

 

 

The Loop

<?php if(have_posts());?>
<?php while(have_posts()); the_post();?>
// Custom HTML and PHP Code
<?php else;?>
<?php endif;?>

The Category Based Loop

<?php query_posts('category_name=
Category&showposts=10'); ?>
<?php while (have_posts()) : the_post(); ?>
// Custom HTML and PHP Code
<?php endwhile;?> 

Theme Definition

/*
Theme Name: Wordpress
Theme URI: http://wordpress.org/
Description: Factory Blog
Version: 2.0
Author: the Factory
Author URI: http://www.thefactory.ro
Tags: wordpress, drupal, joomla, cms
*/

Template Include Tags

< ?php get_header(); ?>
< ?php get_sidebar(); ?>
< ?php get_footer(); ?>
< ?php comments_template(); ?>

WordPress Template Tags

  • <?php the_title() ?> - displays the posts/pages title
  • <?php the_content() ?> - displays the content of the post/page
  • <?php the_excerpt() ?> - displays the excerpt of the current post/page
  • <?php the_time() ?> - displays the time of the current post/page
  • <?php the_date() ?> - displays the date of a post or set of post/page
  • <?php the_permalink() ?> - displays the URL for the permalink
  • <?php the_category() ?> - displays the category of a post
  • <?php the_author(); ?> - displays the author of the post
  • <?php the_ID(); ?> - displays the numeric ID of the current post
  • <?php wp_list_pages(); ?> - displays all the pages
  • <?php wp_tag_cloud(); ?> - displays a tag cloud
  • <?php wp_list_cats(); ?> - displays the categories
  • <?php get_calendar(); ?> - displays the calendar
  • <?php wp_get_archives() ?> - displays a date-based archives list
  • <?php posts_nav_link(); ?> - displays Previous page and Next Page links
  • <?php next_post_link() ?> - displays Newer Posts link
  • <?php previous_post_link() ?> - displays previous link
  • <?php edit_post_link(__('Edit Post')); ?> - displays the edit link
  • <?php the_search_query();?> - value for search form
  • <?php wp_register();?> - displays the register link
  • <?php wp_loginout();?> - displays the log in/out link
  • <?php wp_meta();?> - Meta for administrators
  • <?php timer_stop(1);?> - time to load the page
  • <?php echo c2c_custom('test');?> - displays the custom field1
  • <?php get_links_list(); ?> - display links from Blogroll
  • <?php get_calendar(); ?> - displays the built-in calendar
  • <?php comments_popup_link(); ?> - link of the posts comments

BlogInfo Tags

  • <?php bloginfo('name'); ?> - Title of the blog
  • <?php bloginfo('charset'); ?> - the character set
  • <?php bloginfo('description'); ?> - the description of the blog
  • <?php bloginfo('url'); ?> - the address of the blog
  • <?php bloginfo('rss2_url'); ?> - the RSS URL
  • <?php bloginfo('template_url'); ?> - the URL of the template
  • <?php bloginfo('pingback_url'); ?> - the pingback URL
  • <?php bloginfo('stylesheet_url'); ?> - the URL for the template's CSS file
  • <?php bloginfo('wpurl'); ?> - URL for WordPress installation
  • <?php bloginfo('version'); ?> - Version of the WordPress installation
  • <?php bloginfo('html_type'); ?> - HTML version of the site

BlogInfo Tags

  • is_home() - when the user is on the blog home page
  • is_front_page() - when the user is on the home page
  • is_single() - when the single post displayed
  • is_sticky() - check if a post is sticky
  • is_page() - when a page is displayed
  • is_category() - when a category is displayed

Category based menu 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'); ?>
</ul>

Pages based menu 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='); ?>
</ul>