Today we will teach the second part of a set of two tutorials on how to create a template Wordpres root. If perchance not read the first part, I advise you to do it: Create a wordpress root template (part 1).
From this same article, we will continue to build a slightly more complete template, with the insertion of a sidebar, the blog comments box and also a file page. With the use of the first tutorial and the integration of the second, it is almost easy to design a template for WordPress. However, the examples given here are in order to create a simple and functional template, so if you want you can always equate further development of matter and explore more advanced programming options in WordPress.
STEP 1 – SIDEBAR CREATION
Start by creating a new file in your template directory, with the functions.php name and open it for editing. After that, paste the following code:
What this code does is tell your WordPress your theme has a widget ready sidebar. This code can be easily expanded if you want to place multiple widget areas , for example. We also used to refer to the sidebar of our theme uses a different HTML code that the WordPress usually externalized . What this does is put the sidebar elements involved in <li> tags , which would certainly not beautiful in our theme .
Now let’s draw the sidebar , and should create a new file titled sidebar.php and paste the following code inside .
What this code does is to tell WordPress which will be located your sidebar. It is also putting a default text that will only appear if you have not defined widgets.
Finally, we must include the sidebar in the index.php file of the template , so open that same file and paste the following code after this tag < div id = “content “> :
And congratulations , just created the sidebar of your theme !
STEP 2 – COMMENTS
The comment system WordPress can be simple or complex , depending on your desire , however , taking into account that we are developing a simple template we thought fit to involve a simple comment system.
WordPress puts all simplified with the integration of your comments by default system, which includes a simplistic and functional design, and can be used in any subject, as it comes built into every copy of WordPress . So that’s what we do. Open the index.php file and place the following code after the 13th line (I am referring here to the spot just below the details of posts , the_time type ( ) , etc.)
As you can see , this code portion refers to a file that does not yet have in our theme .
Take the opportunity to test your template , and will realize that he is not smart enough to display the comments box and all comments on the homepage , but when you click an item , it appears as desired . Well … except for the text area that was probably too large. To solve this situation will not go to the core of WordPress edit what is done by the simplest process is to add a line to the CSS , making this process becomes much simpler . So , add the following code to the bottom of your style.css file.
The first line defines a fixed width of 400 pixels to the text box and also includes a padding to make reading more enjoyable. You should now have a simple comment system and at the same time ultra functional in your template.
STEP 3 – FILES
Most websites and blogs on WordPress have a page of ‘files’, which is the place where readers will look for older entries. The common format is made in two lists, one with all the links to the articles by category, and one of the items ordered per month. This makes the files much more functional and simple, easy to read and player navigation.
archives.php is a file usually found by default in WordPress files, and is not necessary “CODAR” no special header to make them appear. However if you want you can try to create a unique and single page for the purpose of the files.
Therefore, create the file and paste the following code in it.
This code may seem to you identical to index.php but if you look carefully you will notice that there is no WordPress loop. This is because we are creating a page with only one item. so we can use still functions as the_title () to collect and present information on the page.
There is also the the_content () function, which will help to put some text on this page feel need. Now in general terms the operation is very simple, is a standard list (actually two …) with two functions, wp_list_categories () and wp_get_archives (). Both functions externalize a listing, and the first lists all the categories of the site and gives you a link that displays all articles within that category. The second is precisely the same, but instead of categories important month of the year in which they were inserted articles.
The parameters in the functions place a counter with the number of articles in each category, to facilitate the reader’s navigation. After that and to add this fantastic page to your blog, you only have to go write a new page and change the “Page Template” to the style “Archives Page” and record. Congratulations your file is online!
STEP 4 – TEST!
Now that it has completed the entire process of inclusion of the sidebar, comments and files on your WordPress template, try to perform some functional tests to verify everything runs like a charm!