Showing posts with label wp theme. Show all posts
Showing posts with label wp theme. Show all posts

Thursday, March 14, 2013

How to Build A WordPress Theme From Scratch

A developer with some accomplishment in CSS and HTML can calmly actualize their own WordPress capacity to accord their website the adeptness to accommodate a different acquaintance for their visitors. This tutorial will air you through the accomplish of creating your own theme.

Understanding How Capacity Work
Before we can cycle up our sleeves and alpha designing an affair we accept to accept how they plan if it comes to WordPress. Aboriginal you charge to accept that there is an aberration amid capacity and templates if it comes to WordPress. The arrangement book is one or added sets of codes that your affair will alarm upon. Templates, like sidebar.php, header.php, index.php, etc., are alleged aloft by the theme. The affair is the accumulating of arrangement files, images, etc. that tells the visitor's browser how your page(s) will look.
  • style.css
  • rtl.css
  • index.php
  • comments.php
  • front-page.php
  • home.php
  • single.php
  • single-<post-type>.php
  • page.php
  • category.php
  • tag.php
  • taxonomy.php
  • author.php
  • date.php
  • archive.php
  • search.php
  • attachment.php
  • image.php
  • 404.php

Setting the Blueprint of Your Theme
For our affair we are traveling to use an appealing basal blueprint consisting of a header, a footer, the capital agreeable breadth and a sidebar.

Basic blueprint for creating your own WordPress theme

To actualize this you will charge to accessible an argument editor.

If you are application an apparatus like Dreamweaver to actualize your affair again set it on the Cipher appearance for now. You can swell use a basal argument editor like Notepad, eMacs or TextMate.

Now that your argument editor of best is open, blazon the afterward curve of cipher and save it as index.html

<html>
<head>
     <title>Our Very Own WordPress Theme</title>
</head>
     <body>
       <div id="wrapper">
          <div id="header">
             header
          </div> <!-- close header -->
 
       <div id="content">
 
          <div id="main">
             main
          </div> <!-- close main content area-->
 
          <div id="sidebar">
             sidebar
          </div> <!-- close sidebar -->
        </div> <!-- close complete content -->
 
          <div id="footer">
             footer
          </div> <!-- close footer -->
       </div> <!-- close wrapper -->
     </body>
</html>

Notice that in the physique of the HTML book we are application div ids to blueprint our theme. Next, we will actualize the alone arrangement files for each.

Create the Arrangement Files
The aboriginal book we are traveling to actualize is the index.php file.

Open up your argument editor and actualize a new book alleged index.php breadth you will access the afterward code:

<?php get_header(); ?>
 
<div id="main">
<div id="content">
<h1>Main Content Area</h1>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></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, we couldn’t find the post you are looking for.'); ?></p>
<?php endif; ?>
</div>
 
<?php get_sidebar(); ?>
 
</div>
 
<div id="delimiter"></div>
 
<?php get_footer(); ?>

Now you can accomplish some changes actuality if you want. Specifically, the argument that reads Capital Agreeable Breadth amid the Tags and the argument that reads Posted on afterwards the Tag can be customized to something that you would rather see on your blog. You can swell change this after if you want, and back these are arrangement files, the changes will be reflected beyond your absolute blog.

WordPress centralized functions will apprehend this book and accept that the affair is cogent those to go out and grab the files appropriate for your page to attending right. This hotlink will yield you to the WordPress Codex page that describes the functions in abundant greater detail.

Now we can actualize the added php files required.

The Footer File

<html>
<head>
<title>My Theme</title>
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>">
</head>
<body>
<div id="wrapper">
<div id="header">
<h1>This is the header</h1>
</div>

The Footer File

<div id="footer">
<h1>This is the footer</h1>
</div>
 
</div>
< ?php wp_footer(); ? >
</body>
</html>

The Sidebar File

<div id="sidebar">
<h2 class="sidebartitle"><?php _e('Categories'); ?></h2>
<ul>
<?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=0'); ?>
</ul>
 
<h2 class="sidebartitle"><?php _e('Archives'); ?></h2>
<ul class="list-archives">
<?php wp_get_archives('type=monthly'); ?>
</ul>
</div>

Now the aftereffect will go advanced and grab the Categories and affectation them as able-bodied as the Archives that will be displayed monthly.

Where is the Main.php file?
No, I didn't overlook a part. The capital agreeable breadth will be busy with the blog posts themselves so we won't be creating a main.php. We do charge to actualize a style.css book though. So let's do that.

body {
    text-align: center;
}
 
#wrapper {
    display: block;
    border: 1px #000 solid;
    width:90%;
    margin:0px auto;
}
 
#header {
    border: 2px #000 solid;
}
 
#content {
    width: 75%;
    border: 2px #000 solid;
    float: left;
}
 
#sidebar {
    width: 23%;
    border: 2px #000 solid;
    float: right;
}
 
#delimiter {
    clear: both;
}
 
#footer {
    border: 2px #000 solid;
}
 
.title {
    font-size: 11pt;
    font-family: arial;
    font-weight: bold;
}


We wouldn't apprehend this to be the accomplished artifact on your blog. In the next allotment of this alternation we will attend at abacus a logo and some added elements to dress up your new theme.

Tuesday, March 12, 2013

How to create a wp theme

In this tutorial, we will apprentice how to accomplish our own acknowledging WordPress affair application Bootstrap. Bootstrap is a acknowledging framework for architecture web sites and applications, and it's a abundant starting point for architecture a acknowledging WordPress theme.

You don't accept to accept congenital a affair from blemish afore to auspiciously chase along. However, we do accept that you are adequate accomplishing things like abacus and alteration posts in the admin breadth or installing plugins.

The affair we will body is based on the Basic business website archetype you can acquisition over on the Bootstrap examples page. For this audience we will body out templates for the afterward pages and functionality:

  • Custom homepage design
  • About page
  • Contact page
  • News area with comments
  • A widgetized sidebar
  • Getting Started
Before we get started there are a few things you will charge to do:
Install WordPress
Download and Unzip Bootstrap
Install the Affair Test Drive plugin*
* You alone charge this plugin if you will be architecture the affair application a reside website and don't wish humans to see the new affair while you are developing it.

Once you accept these things ready, accessible the agenda with all your WordPress files and cross to wp-content > themes.

Once you cross to that binder actualize a new binder alleged “wpbootstrap.” Inside of that binder adhesive in the bootstrap folder.

Inside of that binder actualize a new book called index.php.

Now we're traveling to archetype the antecedent cipher from the archetype basal business website and archetype and adhesive it into the index.php file. Actuality is the antecedent cipher you wish to use. We've just affiliated to a txt adaptation of the cipher back it is too continued to bury in the column here.

Now that we accept a changeless HTML page, we're traveling to move on to creating the capital CSS page. WordPress requires a distinctively formatted animadversion to arise at the top of the style.css page. It uses this animadversion to get all of the meta advice about your theme.

In the aforementioned binder as your index.php page actualize a new book called style.css. WordPress requires a CSS book with the specific name style.css, so we can’t name it annihilation abroad or our affair won't work.

Once you accept created a style.css book at the aforementioned akin as your index.php file, add this animadversion to the top.

/*
Theme Name: My Theme
Theme URI: http://wp-tutorials.blogspot.com/
Description: A demo theme
Author: Badsha Mia
Author URI: http://wp-tutorials.blogspot.com/
Version: 1.0
Tags: responsive, white, bootstrap

This simple theme was built using the example Bootstrap theme "Basic marketing site" found on the Bootstrap web site http://twitter.github.com/bootstrap/examples/hero.html
*/

The endure affair we charge to do afore we install and alpha architecture our new affair is to upload an angel that will arise with our affair in the WordPress admin area. This angel needs to be 300 x 225 px and called "screenshot.png" You can use this angel or actualize your own.

We're now accessible to go into the admin breadth and install our new theme. Login to the admin breadth and go to Appearances > Theme. You should see WP Bootstrap listed as one of the themes.
It’s bright that none of the CSS is alive on this website currently, so in the next footfall we’ll alpha the action of converting this changeless book into a alive WordPress theme.


Most WordPress capacity cover the afterward files:
index.php
style.css
header.php
footer.php
sidebar.php

You will usually see a lot added than these files, but we're traveling to alpha with these files and body from there. Go advanced actualize abandoned files for the header.php, footer.php, and sidebar.php.
What we are traveling to do is yield all of the HTML that would usually be included at the top of every page and cut and adhesive it into the header.php file. Then we will do the aforementioned for all of the HTML that would commonly arise at the basal of every page and cut and adhesive it into the footer.php file.

Let's attending at what anniversary of these files attending like now. Again these are just .txt files that accept been affiliated to because all of the antecedent cipher would be too abundant to account here. You can archetype and adhesive the cipher from these files into your own .php files.