Create your own WordPress theme from scratch [Part 3]

In last part we have coded index.php and header.php,  here we will code content.php, this page will display the posts and search results, and posts under categories, pages , etc.

here is the code for content.php

The above code looks to0 complicated, let me break it for you line by line.

This above line is start of loop, have_posts() this returns true if has any posts or content to be echoed.


is start of header of the article, we assigned the class “entry-header”, then

this h1 tag holds the title of the post, it will be linked to full article so that user can navigate to article by clicking title, the_permalink() this gives the link address to the article, the_title() prints the title of the post.

Here this div tag holds the meta info of posts, such as posting date, time, author of the post. the_time(‘g:i a’); this will give the time of posting in 1:05 am format, the_time(‘c’); this will also give time of posting in 2014-01-19T01:05:21+00:00 format.
totally, it will look like this,


this above line will print the author name and link the name to author’s posts. the_author_posts_link(); must be used for it. and there ends our article header.

here, is the part where the article content is printed.

the_content() prints the content of the article, and that READ MORE is the link to be printed at the end of the preview of article, you can replace it with any words. And here ends the article part.

Here endwhile closes the loop that was started earlier, else: is executed when there are no posts, warning message is displayed when there are no posts to display.

That above code should be just copy paste, it displays page numbers. Do not modify it until you know absolutely what you are doing.

Now, save this code in the content.php

In next part we will code sidebar.php

Create your own WordPress theme from scratch [Part 4]

Create your own WordPress theme from scratch [Part 2]