Under the hood - reboot

I’ve recently received, like phu, inquiries as to how I created the template to drive the front page.

Phu uses a ‘custom’ home.php page derived from some original template code plus a bunch of new code that generate his brilliant
‘two tone’ front door design..

I’m not quite as ‘code savvy’ as Master Phu, so just as a refresher of an older post on this topic - here then, is a basic run down of the code base for the ‘forces index.php.

In the ‘forces instance, `the_post()` is called, generates the first full post (customizable to any number one desires), using a counter to keep track of progress, it then drops down into three separate customizable blocks that contain various elements, such as asides and or del.icio.us links, recent posts and recent comment activity - all of which run within the single `the_post()` loop.

When I first wrote this entry 3 months ago, the forces layout was quite different, filled with posts, asides, del.icio.us, recent comments, pretty much “the works”. While the ‘forces has now been ’slimmed’ down to present a less confused environment for visitors and regulars alike, the core code still remains today, it’s that resilient and re-usable.

So, as a refresher, here is my template code:


``

``


So, this code will create N (where n = $contents) primary posts, drop down into the second block, where I use the minipost plugging to handle my ‘asides’ (one could easily replace the asides with del.icio.us bookmarks, or a link list, etc). From there the code continues to descend down the if.. else.. ladder to spit out recent posts using standard template code - remember we are still in the original the_post() loop so all one needs is to insert the template code for displaying the post title. Finally the code drops through the end while;, where I display recent comments, via brian’s latest comments plugging.

That’s pretty much it. The code base allows for as many ‘primary’ posts as one wishes, is pretty resilient and only uses one loop to generate the page, which cuts down on server processing time & helps keep the whole deal feel ’snappy.

≡ This is a journal entry relating to the topics of No Tags.

Brendan Borlase is a Systems and Network Administrator living in Adelaide, Australia, having lived, worked and breathed Information Technology for over 12 years. Learn more.

Feedback is encouraged. If you would like to read more, consider subscribing to the regularly updated RSS Feed.


  1. If Else

    Nice article. You usually only see things from the outside so it’s great to read about how people are doing things under the hood. Also, I can now direct people towards your article now:-)

    However, I’d seriously question the ‘code savvy’/Master Phu label; I’m still learning things as much as anyone else:-)

  2. brendan

    Heh.. “Master Phu” sounded good at the time.

    There is stuff I learn from your code examples as well :)

  3. Michael Camilleri

    Thank you for publishing this. This is just the thing I was looking for. I wanted to display one full post from the “Weblog” category on my home.php template followed by a list of other recent posts similar to the way Matt Brett and eightface do. I am going to use a simplified version of your code. Thanks again!

  4. brendan

    Michael,

    I’m glad that the code was/ is useful to you and the site you’re working on. :)