WordPress 2.7 Complete

WordPress 2.7 Complete Create your own complete blog or website from scratch with WordPress April Hodge Silver Hasin H...

26 downloads 1596 Views 10MB Size Report

This content was uploaded by our users and we assume good faith they have the permission to share this book. If you own the copyright to this book and it is wrongfully on our website, we offer a simple DMCA procedure to remove your content from our site. Start by pressing the button below!

Report copyright / DMCA form



Then, paste this text into a new file called header.php that you create within your theme folder. Now at the very top of the index.php file (that is, where you just cut the header text from) write in this line of WordPress PHP code:

This is a WordPress function that includes the header.php file you just created. If you save everything and re-load your website now, nothing should change. If something changes, then you've made a mistake.

footer.php

Next, we will create the footer file. To create this, first cut out all of the text at the very bottom of the index.php file, from the footer div, and all the way through the tag. In my case, this is the entire text I cut:
 


Paste the text you just cut into a new footer.php file that you create within your theme folder. Now at the very bottom of the index.php file (where you just cut the footer text from) write in this line of WordPress PHP code:

This is a special WordPress function that includes the footer.php file you just created. Again, you should save everything and re-load your website to make sure nothing changes. [ 144 ]

Download at Boykma.Com

This material is copyright and is licensed for the sole use by Paul Corcorran on 5th July 2009 8601 ave. p #1, , lubbock, , 79423

Chapter 6

sidebar.php

There is just one more essential template file to create. For this one, cut out the entire div containing your sidebar. In my case, it's this text:

Paste this text into a new file in your theme folder called sidebar.php. Now in index.php, add this function in the place you just cut your sidebar from:

This will include the sidebar. In the case of my design, I will want the sidebar on every page. So it's not very crucial for it to be a separate file. I could have included it in the footer.php file. But in some templates, including the default template that came with your WordPress installation, the designer prefers to not include the sidebar in some views such as the Page and single posts.

Your four template files

You've now got four template files in your theme folder: header.php, footer.php, sidebar.php, and the now-much-shorter index.php. By the way, my index.php file now has only the three WordPress functions and the loop. This is the entire file:

">

[ 145 ]

Download at Boykma.Com

This material is copyright and is licensed for the sole use by Paul Corcorran on 5th July 2009 8601 ave. p #1, , lubbock, , 79423

Developing Your Own Theme
Posted in:
Tags:

Not Found

Sorry, but you are looking for something that isn't here.



After creating individual template files my theme folder looks like this:

This whole cutting-and-pasting process to create these four files was just to set the scene for the real goal of making alternative template files.

[ 146 ]

Download at Boykma.Com

This material is copyright and is licensed for the sole use by Paul Corcorran on 5th July 2009 8601 ave. p #1, , lubbock, , 79423

Chapter 6

Archive template

WordPress is now using the index.php template file for every view on your site. Let's make a new file—one that will be used when viewing a monthly archive, category archive, or tag archive. To create your archive template, make a copy of index.php and name this copy archive.php. When someone is viewing a category or a monthly archive of my site, I want them to see an excerpt of the post content instead of the full post content. So, I edit archive.php and replace the_content() with the_excerpt(). Now navigate to a monthly archive on the site by clicking on one of the month names in the sidebar. This is how it will look now:

Instead of showing the full body of the post, WordPress has printed the first 55 words of the content followed by […]. But if you go back to the main page of the blog, you can see that it still displays the full content. This is the power of template files. [ 147 ]

Download at Boykma.Com

This material is copyright and is licensed for the sole use by Paul Corcorran on 5th July 2009 8601 ave. p #1, , lubbock, , 79423

Developing Your Own Theme

Let's make one more change to the archive template. I'd like it to display a message that lets the users know what type of archive page they are on. To do that, just add this code inside copy div:

Archive for the '' Category Posts Tagged '' Archive for



I also added a new style to my stylesheet to color this class dark grey. Now when I click on a month, category, or tag, I see a new heading at the top of the page that lets me know where I am:

[ 148 ]

Download at Boykma.Com

This material is copyright and is licensed for the sole use by Paul Corcorran on 5th July 2009 8601 ave. p #1, , lubbock, , 79423

Chapter 6

Single template

The next template we need to create is for the single post view. To view a single post, you can usually just click on the post title. Right now, the single post page looks like the site's front page (because it's using index.php); except with just one post. At the very least, this page should have a comment form added! To get started, again make a copy of index.php and name the copy single.php. This is the template that WordPress will look for first when it's serving a single post. If it doesn't find single.php, it'll use index.php. To add a comment form to single.php, simply add the following code just before :

Now when you view an individual post, you'll see that the comment form has appeared.

[ 149 ]

Download at Boykma.Com

This material is copyright and is licensed for the sole use by Paul Corcorran on 5th July 2009 8601 ave. p #1, , lubbock, , 79423

Developing Your Own Theme

WordPress prints the