Announcement!

Bid Oh Bid Directory - Bid your link to get higher position now!

You are reading Make your Own Wordpress Theme - Part 3. To read other parts, click on the link below.

Now we will going into the hard part. Index.php file is the core file in our theme file.

Hopefully your index.php will look like this. (Read Part 1 - The Layout )

Code (html4strict)
  1.  
  2. <div id="main">
  3.  main
  4.  </div> <!– close main –>
  5.  

Call Template Files

Now what we want to do is to call our header.php, sidebar.php and footer.php into our index.php file. To do this we need these functions.

<?php get_header(); ?> - This function will call our header.php file
<?php get_sidebar(); ?> - This function will call our sidebar.php file
<?php get_footer(); ?> - This function will call our footer.php file

Put <?php get_header(); ?> above main id and <?php get_sidebar(); ?> and <?php get_footer(); ?> below the main id like this.

Code (php)
  1.  
  2. <?php get_header(); ?>
  3.  
  4. <div id="main">
  5.  main
  6. </div> <!– close main –>
  7.  
  8. <?php get_sidebar(); ?>
  9. <?php get_footer(); ?>
  10.  

The Loop

Ok whats next? Now we are going to dive into the Wordpress loop. Yay… :d This loop is use to display our posts on our website.

The loop start with this

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

and will end with this. I will explain why we need “else:” later. :)

<?php endwhile; else: ?>

After the <?php endwhile; ?>, make sure to close the if with <?php endif; ?>.

Put all these functions in our main id and our index.php will be like this.

Code (php)
  1.  
  2. <div id="main">
  3.  
  4. <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  5.  
  6. main
  7.  
  8. <?php endwhile; else: ?>
  9. <?php endif; ?>
  10.  
  11. </div> <!– close main –>
  12.  

Now we will focus in the loop. In loop, we will make three div classes. This is use to put our post title, post content and post date, time, etc.

Remember, we are only focus in the loop. Put these div’s in the loop.

<div class=”post_title”>
post title here
</div> <!– close post title –>
<div class=”post_content”>
post content here
</div> <!– close post content –>
<div class=”post_tag”>
post tag here
</div> <!– close post tag –>

Our loop will look like this.

Code (php)
  1.  
  2. <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  3.  
  4. <div class="post_title">
  5. post title here
  6. </div> <!– close post title –>
  7. <div class="post_content">
  8. post content here
  9. </div> <!– close post content –>
  10. <div class="post_tag">
  11. post tag here
  12. </div> <!– close post tag –>
  13.  
  14. <?php endwhile; else: ?>
  15. <?php endif; ?>
  16.  

Post Title

For the post title, we use these tags.

<?php the_ID(); ?> - Call our post id to put in our post_title div as id
<?php the_permalink() ?> - Call our post url
<?php the_title(); ?> - The title of our post

In post_title class, we create our post title with link to the post. Here is the HTML + PHP code.

<a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title(); ?>”><?php the_title(); ?></a>

And include the post id in our post_title div and it will look like this.

Code (php)
  1.  
  2. <div class="post_title" id="<?php the_ID(); ?>">
  3.  
  4. <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
  5.  
  6. </div> <!– close post title –>
  7.  

Post Content

In content, we only need one tag to call our post content. The tag that we will use is this.

<?php the_content(__(’Read more…’)); ?>

Note: You can change “Read more…” to something else.

Code (php)
  1.  
  2. <div class="post_content">
  3.  
  4. <?php the_content(__(‘Read more…’)); ?>
  5.  
  6. </div> <!– close post content –>
  7.  

Post Tag

In post tag, I usually put date, time, category and link to the post comment. And I also put a link to edit the post (only viseable if login).

<?php the_time(’F dS, Y’) ?> - Call post date
<?php the_time(’h:i a’); ?> - Call post time
<?php the_category(’, ‘) ?> - Call post category
<?php comments_popup_link(’No Comments’, ‘1 Comment’, ‘% Comments’); ?> - Call the comment link
<?php edit_post_link(’Edit’,”,”); ?> - Call the post edit link

We put all these tags into our post_tag div.

Code (php)
  1.  
  2. <div class="post_tag">
  3.  
  4. <?php the_time(‘F dS, Y’) ?> | <?php the_time(‘h:i a’); ?> | <?php the_category(‘, ‘) ?> | <?php comments_popup_link(‘No Comments’, ‘1 Comment’, ‘% Comments’); ?> | <?php edit_post_link(‘Edit’,,); ?>
  5.  
  6. </div> <!– close post tag –>
  7.  

Done! Phew… #:-s

Call the Comments

After we end with the post part, we need to call our comments (will be discussed in Part 4 - Comment). Use this

<?php comments_template(); ?>

and put it before the endwhile tag.

Code (php)
  1.  
  2. <?php comments_template(); ?>
  3. <?php endwhile; else: ?>
  4.  

If 404 Error

Maybe some of you wonder why I put “else:” after the endwhile. It is use to display an error text if the page/post is not available.

Just type in any text that you want to display after the else tag. I will type this.

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

And it will look like this.

Code (php)
  1.  
  2. <?php endwhile; else: ?>
  3.  
  4. Sorry, but you are looking for something that isn‘t here.
  5. <?php endif; ?>

Finally your index.php hopefully will become like this. :)

Code (php)
  1.  
  2. <?php get_header(); ?>
  3. <div id="main">
  4.  
  5. <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  6.  
  7. <div class="post_title" id="<?php the_ID(); ?>">
  8.  
  9. <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
  10.  
  11. </div> <!– close post title –>
  12.  
  13. <div class="post_content">
  14.  
  15. <?php the_content(__(‘Read more…’)); ?>
  16.  
  17. </div> <!– close post content –>
  18.  
  19. <div class="post_tag">
  20.  
  21. <?php the_time(‘F dS, Y’) ?> | <?php the_time(‘h:i a’); ?> | <?php the_category(‘, ‘) ?> | <?php comments_popup_link(‘No Comments’, ‘1 Comment’, ‘% Comments’); ?> | <?php edit_post_link(‘Edit’,,); ?>
  22.  
  23. </div> <!– close post tag –>
  24.  
  25. <?php comments_template(); ?>
  26. <?php endwhile; else: ?>
  27.  
  28. Sorry, but you are looking for something that isn‘t here.
  29. <?php endif; ?>
  30. </div> <!– close main –>
  31. <?php get_sidebar(); ?>
  32. <?php get_footer(); ?>

Next, Part 4 - Comment . [tags]diy, how to, skin, theme[/tags]

Subscribe me feed! If you enjoyed this article, get latest updates via RSS feed or by email.

37 Responses to “Make your Own Wordpress Theme - Part 3”

  1. ikram_zidane
    December 14th, 2006 | 6:48 pm

    seriously, do u know that you could only call for the comment template in single.php or page/php ?? or am i wrong…. index is to show the posts. :-?

  2. CypherHackz
    December 14th, 2006 | 6:53 pm

    we can call the comment from index.php as long as there is no single.php or page.php in our theme folder. i tried them so many times lol… btw i wil put the extra info in Part 7. Wait la… :d

  3. Undertypo
    December 14th, 2006 | 7:34 pm

    Agree. Ikram go and download Simple theme and tried it. It consists only header, index. sidebar,comments and footer php files only.

  4. novatech
    December 14th, 2006 | 8:36 pm

    believe it or not. you can create theme in single index.php
    but, why do something like that, it just gonna screw your ass when editing it. lol
    template is something suppose to be easy managed right?

  5. CypherHackz
    December 14th, 2006 | 8:59 pm

    know what. my first theme that i ever make was in index.php only. :d

  6. ikram_zidane
    December 14th, 2006 | 10:13 pm

    Agree. Ikram go and download Simple theme and tried it. It consists only header, index. sidebar,comments and footer php files only.

    any idea on where would i do that ? thanks..

    and yeah.. its possible.. but i dont think u should do that..
    http://www.scoutpress.de/downl.....rarchy.png
    here the hierarchy and how the template could / should / would stand..

  7. champoo
    February 12th, 2007 | 9:43 am

    nicely done thanks,

    I try your code and got this error msg

    arse error: syntax error, unexpected T_STRING in /home/xxxxx/public_html/blog/wp-content/themes/champoo/index.php on line 41

    which is this on line 41

    something was wrong ? please help a noobie >__>”

    thank you.

  8. champoo
    February 12th, 2007 | 9:45 am

    nicely done thanks,

    I try your code and got this error msg

    arse error: syntax error, unexpected T_STRING in /home/xxxxx/public_html/blog/wp-content/themes/champoo/index.php on line 41

    which is this on line 41

    something was wrong ? please help a noobie >__>”

    sorry for double post

    thank you.

  9. CypherHackz
    February 12th, 2007 | 10:32 am

    check your index.php file on line 41. maybe there is some code error in your php file. or send the file to me and let me check what could be wrong.

  10. khairilz
    March 2nd, 2007 | 6:29 pm

    xpe ke ada nombor tu..dari 1 hingga la belas2..aku main copy and paste je kat dalam notepad..
    atau kena buang nombor tu..Nombor kat tepi belah kiri tu

  11. Mamai
    March 7th, 2007 | 3:22 pm

    Hello,

    Can someone help me, I planning to create & add the single.php on my current template but I don’t know how to integrate or link that on my template.
    :((

  12. CypherHackz
    March 8th, 2007 | 8:23 am

    your single.php will be displayed when you view in single post. :)

  13. Camay123
    March 8th, 2007 | 11:59 am

    I got an error loading website.

    So I copied and paste your whole index.php text into a new file, called it index.php , and I still get this error :

    Parse error: syntax error, unexpected T_STRING in /home/bonsaira/public_html/blog/wp-content/themes/blackor/index.php on line 14

  14. CypherHackz
    March 8th, 2007 | 1:22 pm

    can you send the index.php to me via email? i will check what i s wrong. thank you.

  15. Camay123
    March 8th, 2007 | 9:19 pm

    [Comment ID #26840 Will Be Quoted Here]

    Done.

  16. Make your Own Wordpress Theme - Part 1 at CypherHackz.Net
    June 8th, 2007 | 10:30 am

    [...] Part 3 - Index [...]

  17. Trevor
    January 29th, 2008 | 1:23 pm

    I am getting the same parsing error as the other people mentioned earlier. Have you been able to look at their files and determine what is causing that? Should I send you my file, too because the parsing error is located on line 8 for me. I know that it could be the same thing and just on different lines because everyone writes their code differently.

  18. CypherHackz
    January 29th, 2008 | 3:54 pm

    it is because of the apostrophe. Wordpress displays it in wrong way. That is why you get the error.

  19. Aliya
    January 30th, 2008 | 3:54 pm

    Nice tutorial…i am new to cms and word press..was studing it for a while but couldnt find anything to dsign my own template…but after this tutorial I can …..Thank you so much!!!!

    In case i find some problem I will contact u…

  20. Voltron
    February 29th, 2008 | 6:45 am

    im still getting the parse error… which apostrophe is it? is one of them incorrect? thank you for your time.

    | | | |

    there are a lot of them… :)

  21. CypherHackz
    March 2nd, 2008 | 8:41 am

    All of the apostrophe need to be corrected. Just use the replace function mate. :D

  22. mr magoo
    March 29th, 2008 | 12:55 am

    What do you replace the apostrophe’s with?

    great site and thank you!

  23. khaiza
    May 16th, 2008 | 11:23 pm

    can you please tell me how to display multiple post when we click in category link? I searched everywhere how to display multiple post but i still found single post display..somebody help me please….

  24. CypherHackz
    May 19th, 2008 | 7:24 pm

    When you click on a category link, it will display a list of posts inside in the category.

  25. Aimee
    May 31st, 2008 | 4:48 am

    Hi. I have been using the tags as references for a layout I am integrating. The special characters such as ,’ ” have messed me up terrible. The PHP keeps coming up with syntax errors which forces me to individually replace the special tags with normal tags scuh as , “”, etc.

  26. WJwoZ
    June 22nd, 2008 | 10:26 pm

    Have You Seen This Already?, business plan format free example, business plan format free example, 45119,

  27. rdoKX
    June 23rd, 2008 | 9:06 am

    Have you seen this site?,

  28. zispT
    June 23rd, 2008 | 10:31 am

    Must See!!! A Promising Site,

  29. FKoGl
    June 25th, 2008 | 10:19 am

    Very HelpfulHow Do You Do that? , cam chatting free nude web, cam chatting free nude web, 081,

  30. EvSouL
    July 25th, 2008 | 6:58 am

    Hey thanks for the howto. I already know CSS and all that so it was nice to learn the basic structure of making a wordpress theme.

    Once again thanks!

  31. billyduc
    August 22nd, 2008 | 1:41 am

    Parse error: syntax error, unexpected T_STRING in …\index.php on line 13
    My line 13
    I try to replace with but still this error ?
    I read these comments above…someone help the same problem with me…It’s very nice if you publish a clear text file..because when copying and pasting I have these # character along…Thanks you !

  32. Pagerank
    September 13th, 2008 | 10:48 pm

    Great Blogg!!! Worth Digging…Check out my site too @pagerank

  33. radar love
    September 23rd, 2008 | 5:44 pm

    hey cyperhack did you hear all the comment that get error page from your tutorial ?

    you should solve that one by one, because you has already make tutorial for this..

  34. radar love
    September 23rd, 2008 | 5:57 pm

    let me help other..

    just replace the ” with ” on your ordinary keyboard

  35. radar love
    September 23rd, 2008 | 6:04 pm

    your template is sucks i got error everywhere … shit..

    you only wasting my time

    better you closed all of your theme tutorial..

    dumbass

  36. phyr3al
    October 12th, 2008 | 6:51 am

    At ‘RADAR LOVE’.

    you’re an impatient Idiot and a dumbass yourself. Im sick of reading comments from unhelpful f#$kw&ts like yourself who bitch and moan at people who are actually trying to help others.

    So you got some errors, whoopee, if you’re so talented then maybe you should figure it out yourself or maybe its your shit English thats causing the errors?

    mahunga kaka….

  37. Dana
    December 2nd, 2008 | 3:45 am

    This was much better, I appreciate your taking time to explain the tags here. It was very clear, concise, and helpful. Thanks so much.

Leave a Reply