PDA

View Full Version : break lines after dates on blog posts



kaboomboom
20 Jul 2010, 12:11 AM
Hi,

I'm currently attempting to build my first blog using PHP. I'm doing pretty well so far, and I've got a fully functional blog with archives and comments set up.

My question, I am trying to set it up so that I can create line breaks after the date changes between blog posts. For example, if I post two entries on July 19th, then one entry on July 20th, the two blog posts on July 19th will be grouped together in the same "Date Posted" while the July 20th post will start a new "Date Posted" section. An example of this kind of blog is found on the woot.com blog, http://shirt.woot.com/Blog/ .

Help me, PHP gurus!

Thanks.

TheMichael
21 Jul 2010, 12:16 AM
This sounds like a logic question, not so much a PHP-specific question.

Here's the logic you need to examine:

A. Loop through the articles you want to display
B. Compare the date of the present article with the date of the previous article
C. If the date is different or no previous date has been stored, insert a line break (you could split this up into two if statements if you dont want a line break on "no date has been stored")
D. Display the article
E. Remember the date of this article in a variable for comparison on the next article

Pseudo Code:

if(!$rememberedArticleDate || $rememberedArticleDate!=$currentArticleDate) {
// ... insert the break (html stuffs)
}
// display article (html stuffs)

$rememberedArticleDate = $currentArticleDate;