The Simplest WordPress Blog
So I like to start all my Wordpress theme designs with a very simplistic Wordpress base and then add all the complicated functionality found in my themes. I think it is a useful learning tool for the beginner to get used to Wordpress programming. So here’s my guide for setting up a really simple blog.
First of all go to your wordpress root and find the folder wp-content/themes/ and create a new folder with the name of the theme you’d like. Then set up the meta for the theme. This includes setting up the theme name, description and author, this is done by writing a few details in a new file that you need to create called style.css. At the top of the file put some of the details for your theme, you can replace the details that I have entered for your own:
1 2 3 4 5 6 7 8 9
We’re not going to be putting anything in the css file, but you may want to put in resets for the most commonly used attributes at the beginning, there are loads of these css code segments on the internet and you just need to to pick one and slightly alter it for you particular site, search for style reset in google :).
Then we’ll add the index.php, the glue that holds the rest of the files together. First of all we’ll create the main Wordpress loop, as this is the most important part of the design. This is the main part of your site, generally on the front page, that displays a selection of your posts.
1 2 3 4 5 6 7
Now this code is just checking if any posts exist and then looping through all the posts in reverse chronilogical order. Now inside the loop nothing is happening so whats the point? Well now we can add some special wordpress functions that will extract the information from each post that we loop through. The code also supplies an error message if there are no posts to display.
1 2 3 4 5
These functions are simple enough and are easily used within the loop shown previously, the only slight different is with the_content() function which takes a string as a parameter, this just provides the words for the more text link.
For showing how many comments a post has, still inside the loop, we have a slightly more complicated bit of code. First we have to check certain conditions:
1 2 3 4 5 6
Here we check if the post allows for comments first, create a div for each case and then use the comments_popup_link() function with parameters showing what words we’d like to show for each case particular case of comment status. It’s pretty easy to work out what each parameter corresponds to from the example given above.
So thats it for the loop, we obviously have to add a bit more divs and css styling to get everything formatted in the correct way but that goes beyond the scope of this tutorial.
One further bit of code to add after the end of the loop but still inside the if(have_post()) function is the code for pagination. Again wordpress makes this simple and is just a matter of adding:
We then have to include the header, sidebar and footer pages which we’ll quickly create in a minute. This is easily done using the built in Wordpress functions as follows. Adding this function to the top of the index.php file:
And then to the bottom of index.php:
These functions pull in the the header.php, sidebar.php and footer.php repectively, and we’ll create these files now. First we’ll create the footer.php as it is simpler. All we need to do is add this code to the file:
1 2 3
The wp_footer() function provides a hook to the footer of the page which Wordpress and Wordpress plugins can utilize. The rest of the file is just the closing of the html tags: body and html, which we will open shortly in the header.php file.
The sidebar.php gives the code for the sidebar on the site, this is quite a common wordpress blog feature. We’ll check to see if the their are any widgets loaded in the primary widget area and if not we’ll put our own in. Then we’ll add a secondry widget area for less important widgets.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
Now a lot of what is contained in the header.php file is the standard html head code which contains detailed information about your site, now Wordpress again makes this slightly easier by using specific functions, but really most of it is just a copy and paste job.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
The only things to take note of are the rss and atom lines that will automatically generates rss and atom feeds using wordpress functions. Also the final line which creates your blog title and links it to your homepage. Apart from these it is pretty each to tell exacty what each wordpress function is doing.
Now as long as you have customized the look and format of your blog using some div’s and css you have yourself a front page that shows off your latest posts. At the moment the hyperlinks associated with each post have not been implemented, this will be covered in the 2nd half of this tutorial where we will be looking at individual post pages, the comments for each post and the comment input form.