/    Sign up×
Community /Pin to ProfileBookmark

My Custom Blog, Help!

Hey everybody! I have developed my own blog and everything is working great except I can’t figure out how to get the “Monthly Archives” section to work properly. I have the blog posts stored in a database along with the date they were posted (ex: 05/22/2008) and I’m trying to figure out how I can print every month in which there was a blog posted and how many posts there were for each month. If you go to [URL=”http://alive.ccgulfbreeze.com/blog/”]this link[/URL] you can see, on the left side, the “Monthly Archives” section, and below it you will see that May 2008 is printed 4 times, this is because I have 4 blog posts for May, this is my problem, how can I make it so it will only print May 2008 once, but still count how many posts were posted for that month.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@SyCoMay 22.2008 — Nice looking blog you have there.

I presume you already have your list of months so if you set the key it'll build a unique array. If you build a second array with the first key unique like th first but allow it to build its own keys you'll be able to count it.

Something like this[code=php]

$monthslist=array('jan','feb','march','march','march','april','may');
foreach($monthslist as $month){
$display[$month]=$month;
$displaycount[$month][]=$month;
}

foreach($display as $k => $v){
//$k is the month key
echo '<br>'.$k.' ';
echo count($displaycount[$k]);
}[/code]


jan 1

feb 1

march 3

april 1

may 1
Copy linkTweet thisAlerts:
@cs3mwMay 22.2008 — Have you resolved this issue?
Copy linkTweet thisAlerts:
@GreyfishauthorMay 22.2008 — I just got it to work with the code posted below...but I think its pretty crappy coding...I'm not sure though. I'm going to try to use SyCo's code.

Here is what I did...
[code=php]
while ($listMonth = mysql_fetch_array($getPost)){
$postDates[] = substr($listMonth[postDate], 0, 2);
}

$i = 0;
while ($postDates){
$count = array_count_values($postDates);
if ($postDates[$i] != $postDates[$i+1]){
$monthDate = mktime(0, 0, 0, $postDates[$i], 01, 2008);
echo date("F Y", $monthDate) . $count[$postDates[$i]];
}
$i++;
}
[/code]
×

Success!

Help @Greyfish spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...