Simpler, Single Loop WordPress Theme Creation

Recently I’ve been making alot of wordpress themes (just not my own) I always like to keep the files to a minimum. In wordpress, the loop.php file is the traditional one to handle displaying all the posts, pages, media, and anything else you can look at in wordpress. The official wordpress themes, and countless others, use multiple “loops”, one for the main page, one for the an individual post, and even one for the pages in some themes. This clutters up the files and generally makes things a mess. I created a simple function to call that lets me filter things instead. First, you need this in the theme functions.php file

Snipplr: http://snipplr.com/view/58053/simple-single-loopphp-word-press-theme-function/

Then, instead of requiring the loop.php file in your theme index you just insert the new the_loop() function, with all of the items you want filtered out. You can use whatever arbitrary names you’d like, just use the same names in your master loop. First you call the loop like this:

Snipplr: http://snipplr.com/view/58053/simple-single-loopphp-word-press-theme-function/

Then you program your loop to use the display() function to determine if it’s going to show that, in the example above it would look like this:

Snipplr: http://snipplr.com/view/58053/simple-single-loopphp-word-press-theme-function/

In that case it will show the header and the content (since we didn’t tell it not to when calling the_loop() but won’t call the comments or meta because we did. Pretty simple little bit of code that saves a lot of time in the long run since now everything can be in one file and if you change something you only have to look in that same file. Thats it for now, it’s been a long week. Next week I hopefully will be starting on the new theme for this site as well as posting something a little meatier, a simple modular site system.

Leave a Reply

Your email address will not be published. Required fields are marked *