Forum Moderators: coopster
I have a basic news archive that is currently just looping and outputting everything from mysql into a basic list, ordered by date. What I'd like to do is to have it nicely formatted by dates in an archive like format, listing old entries by year or month (depending on how close to todays date the entry is) and newer entries (this month) by date.
Similar types of archive layouts can be found at: [gov.sk.ca...]
[cs.dal.ca...]
Basically, I just want to make it a little bit nicer and more organized than outputting everything, post by post, in a huge long list.
Can anyone help out?
Thanks,
gen
A thought would be instead of hitting mysql everytime you could have it be static and generate it monthly (or some time increment) from the db to an actual html page
though that doesn't really address the question.
what are you thinking of doing? are you just asking about layout?
Basically it's a formatting thing. Instead of:
Dec 30, 2006: News title here.
Dec 31, 2006: News title.
Jan 04, 2007: More news titles..
etc.
I'd prefer to break it up into smaller, more organized groups. Something - ANYTHING - better than a massive list of what's in the database, sorted by date DESC or whatever. Some sort of small function to break it up into an easier read grouping.
Any one of those ideas would work..
Thanks for the input :)
gen
[edited by: jatar_k at 9:09 pm (utc) on Jan. 30, 2007]
I don't really know, it's really just a fomatting thing, you can format them however you like. It's hard since they are grouped and relate chronologically then you need to show them that way. If you came up with a different type of classification for the articles then they could be listed by topic or category.
I just need to find a simple way to order these posts dynamically and by date - anything better than the current situation.. irregardless, it'll get sorted out for V2 this quarter.
Ah well.. cheers and thanks anyway.
gen
[edited by: jatar_k at 3:08 am (utc) on Jan. 31, 2007]
[edit reason] no urls thanks [/edit]
If you are going to group them then you have to create the group, a common criteria or attribute that you can use in your select statement.
You don't have much there so you could design a category system. Within those categories I imagine you would still group them by date, though you don't have to.
and don't worry, Google hates all of our guts ;)
<?php
$news = array(
array('postedTimestamp' => strtotime("+1 day"), 'headline' => 'Headline 1'),
array('postedTimestamp' => strtotime("+2 day"), 'headline' => 'Headline 2'),
array('postedTimestamp' => strtotime("+2 day"), 'headline' => 'Headline 3'),
array('postedTimestamp' => strtotime("+5 day"), 'headline' => 'Headline 4'),
);
//print_r($news);
$nl = "
";
$count_news = count($news);
$date_last = '';
for($i=0; $i<$count_news; $i++){
$date_current = date("Y-m-d", ($news[$i]['postedTimestamp']));
$date_next = (isset($news[$i+1]))? date("Y-m-d", ($news[$i+1]['postedTimestamp'])) : '';
if( $date_current!= $date_last ){
echo '<h2>'.date("l", ($news[$i]['postedTimestamp'])).'</h2>'.$nl.'
<ul>'.$nl;
}
echo '<li class="'.(($i%2 == 0)?'even':'odd').'">'.$nl;
echo '<h3>'.$news[$i]['headline'].'</h3>'.$nl;
// echo more news details here
echo '</li>'.$nl;
if( $date_current!= $date_next ){
echo '</ul>'.$nl;
}
$date_last = $date_current;
}
?>