Create my first theme
To start building your theme, first create a sub-folder in the wp-content/themes directory in your WordPress folder.
After creating the Directory for Theme Folder, create the following files inside folder –
header.php – This file will contain the code for the header section of the theme;
index.php – This is the main file for the theme. It will contain the code for the Main Area and will specify where the other files will be included;
sidebar.php – This file will contain the information about the sidebar;
footer.php – This file will handle your footer;
style.css – This file will handle the styling of your new theme;
The header.php file
Basically, this is simple HTML code with a single line containing a php code and a standard WordPress function. In this file you can specify your meta tags such as the title of your website, meta description and the keywords for your page.
<html> <head> <title>Tutorial theme</title> <!-- part of the line is a WordPress function that actually loads the stylesheet file.--> <link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>"> </head> <body> <div id="wrapper"> <div id="header"> <h1><a href="<?php bloginfo('url'); ?>"><?php bloginfo('name'); ?></a></h1> </div>
The index.php file
</pre> <?php get_header(); ?> <div id="main"> <div id="content"> <h1>Main Area</h1> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <h1><a href=”<?php the_permalink();?>”><?php the_title(); ?></a></h1> <h4>Posted on <?php the_time('F jS, Y') ?></h4> <p><?php the_content(__('(more...)')); ?></p> <hr> <?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?> </div> <!-- This will include the sidebar.php and in this file you can display your post categories, archives etc.-- ><?php get_sidebar(); ?> </div> <div id="delimiter"> </div> <!-- which will include the footer.php file in your page. --> <?php get_footer(); ?>
The Sidebar.php file
<div id="sidebar"> <h2 ><?php _e('Categories'); ?></h2> <ul > <?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=0'); ?> </ul> <h2 ><?php _e('Archives'); ?></h2> <ul > <?php wp_get_archives('type=monthly'); ?> </ul> </div>
The Style.css file
body { text-align: center; } #wrapper { display: block; border: 1px #a2a2a2 solid; width:90%; margin:0px auto; } #header { border: 2px #a2a2a2 solid; } #content { width: 75%; border: 2px #a2a2a2 solid; float: left; } #sidebar { width: 23%; border: 2px #a2a2a2 solid; float: right; } #delimiter { clear: both; }