Forum Moderators: coopster

Message Too Old, No Replies

archive dated news posts

         

generic

7:57 pm on Jan 30, 2007 (gmt 0)

10+ Year Member



Hi,

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

jatar_k

8:13 pm on Jan 30, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



too bad those examples don't work in Moz, darn it sask ;)

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?

generic

8:43 pm on Jan 30, 2007 (gmt 0)

10+ Year Member



Hi - thanks for the reply.

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]

jatar_k

9:12 pm on Jan 30, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



sorry, I did see the first ones, I switched to IE, though admittedly you chose all good urls, no need for too many examples. ;)

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.

generic

2:52 am on Jan 31, 2007 (gmt 0)

10+ Year Member



I guess I was kind of hoping that there might be a way to sort and group it with SQL before it outputs.. I'm sure I've seen that before but I can't find any related posts in my searching - bad criteria I guess. (or google hates my guts, which is also plausible)

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]

jatar_k

3:10 am on Jan 31, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you can but as I said, you have to have something to base the sort on.

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 ;)

whoisgregg

3:06 pm on Jan 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you sort them by date, then you can chunk them by date using code like this:

<?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;
}
?>