BInterest

Blog of Ur Interest

Understand & Create Prefect Wordpress Loop Code


Heart of the Wordpress Blog is the Loop Code, which runs on and on your wordpress blog as per you need and preferences. While making theme for BInterest.com, learn about what the hell is this loop ? and How to  create a prefect loop for your blog ? So just thought of sharing with you all wordpress lovers around the world What, Where, Who and How about Wordpress Loop code ! Understand & Create

The Major Reason for this Post on Wordpress Loop Code is, 90% of the Wordpress theme download have very very sloppy and hard to under the loop code. More and More people around the world are attracted towards wordpress and most of them would be in need of there unique design (One of the Most Important Rule to have a Successful Blog) with here and there modification in the downloaded themes.

As per the Wordpress Codex, it is clearly mentioned that LOOP is piece of code used by wordpress to display posts on the current page according to specify criteria withing the loop.

The Loop is used by WordPress to display each of your posts. Any HTML or PHP code placed in the Loop will be repeated on each post. …. Loop Wordpress Codex

Wordpress Loop can be found on most of the theme pages, which allow you to show the post on the blog, In short all the major post code files like index.php, single.php, category.php, archive.php and page.php . Lets First Look at the How to Wordpress Loop Look like.

// The loop starts here:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
// and ends here:
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>

Now that, you know, where you can find wordpress loop, and how to it look like, lets understand and answer the Question like What does it Means and How do it work ?

If you see it carefully, the above code is nothing but the standard PHP While() Function embedded with end while statement;

The Loop Start up say some thing like this “if (have_posts)“, which means “Check if if any of the posts are available  within Wordpress database to display” if you want to understand the detail function of the if (have_posts), that is very clearing posted on Double Black Design tutorial on Wordpress Loop.

Second Part of Wordpress Loop Start-up Codes say something like this “while (have_posts()” which means “Above process of Checking is looped or repeated for each post  available for display in the Wordpress Database

Last Part includes : “the_post();” which means “check the next post ready to display and if the answer is Yes, Display and if Not then Display Nothing” you can also say that it retrieve the next available post from the list of post available in the wordpress database.

You can see the Loop in Action at Wordpress Codex. Coming on to the End of the Wordpress Loop : “endwhile; else code implies that “if there was nothing to display in the have_post() function display the below code,. which says Sorry, No Post Matched

The line displaying the code “endif” tells “the wordpress database that wordpress loop ends here.

Hoping, that I would be successful in making you all understand what the hell is this Wordpress Loop, as I am not at all a coder, i am just a blogger, who have started loving coding and feels that every bloggers on internet should learn the same.

If you are interested in creating the post excerption with the Thumbnail on the Home Page then you would be reading Wordpress post excerpt() Tutorial.

Would be posting shortly, How to create a prefect Index Page for your Wordpress Theme, flowing the standard rules, so that every one seeing your source code could understand and learn the same.,

You can follow me on Twitter at http://twitter.com/binterest.Do stay tuned to Binterest.com for more, Best Way 2 do it, Subscribe to Binterest's Feed Updates



Related Post :

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.



No Speak Out ! »

Be First to Speak Out Your View.,

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    Hey, Look @ me I Write this !

    BInterestWelcome to Binterest.com | Am Analyst Cum Blogger, who likes to blog about Free Software, Webware, Giveaway, Firefox & its Add-ons, Tips & Tricks on Microsoft Office 2007 & 2010, Vista & Windows 7, Google, Microsoft. Sharing info which i thing would be worth sharing with readers like U

    Find Me Elsewhere

    Google Profile Twitter Facebook Deviantart Linkedin