Step 3 - Guts and glory - The real content

Filed Under: Themes, Wordpress

So you think that you are ready for Step 3? Great! Now that you have the basic files set up lets go ahead and get things going.

Wordpress uses what is called a loop to display their content. Basically what it does is it tells the server to go into your MySQL database and display however many posts that you have. You can go into your dashboard and tell it to only disply two posts on your homepage or how ever many posts you want displayed on your homepage. It will display however many posts you tell it, unless you do not have that many yet. Go ahead and open up your file that you want all your articles to display in. If you want the articles on the right side and a sidebar on the left side, then open up the right side, otherwise open up the leftside file.

Now copy the code from your single page layout, that is just for displaying the articles, and paste it into your file that you want the article display to be in. Lets look at how to start the loop first.

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

Okay, so this code needs to go wherever you want your loop to start. So, if you say have a div tag in your code that contains the code for every article. So, if you need to have the article in that div everytime, put the loop start there. The loop will than create the code that is inside the loop everytime that a article is displayed. Now let’s set it up to end the code.

<?php endwhile; else: ?>
	<?php _e('
           Sorry, no posts matched your criteria.'); ?>
	<?php endif; ?>

Okay, these lines need to go wherever you want the loop to stop. So, with the example, this would after the ending div tag for your main article div. What this code is doing is telling that server that, if there is no article matching what the user is trying to get to, to display “Sorry, no posts matched your criteria.” on the page and not display anything else inside the loop. and than it tells it to end the loop if it does not meet that. That’s it. You have your basic loop set up.

Now you may be wondering why when you upload this file, your lovely Hello World post does not show up on the screen. Well, simple. All you are doing is telling the loop to display what is inside of the loop how ever many times you have set inside of your dashboard. You are not calling anything from the database to be displayed. Now, Wordpress has an awesome codex page. Visit it, read it, sleep with it, memorize that thing as much as you can! Now, go do it! Wordpress Codex Page

Look up codes on that page, and implement them until you get what you want. If you need some assistance or jsut have some basic questions, stop by and send me a email on our contact page. Stay tune and check back soon for Step 4 - Categorizing yor posts.

Copyright © 2007-2008 StyleYourBlog
Website Developed by BAMJr. Designs
Log in