Blogs Archives
3 posts by 2 authors in: Forums > CMS Builder
Last Post: May 25, 2011 (RSS)
By design9 - May 25, 2011
Hello, I am using the following code in my blog menu to show a list of the available blog archives by month and year so when you click on the link, it takes you to the blog archives for only that month.
<?php // get list of unique months and years with articles
$query = "SELECT DATE_FORMAT(date, '%M %Y') as dateAndYear, YEAR(date) as year, MONTH(date) as month FROM cms_blogs GROUP BY dateAndYear ORDER BY date DESC";
$result = mysql_query($query) or die("MySQL Error: ". htmlspecialchars(mysql_error()) . "\n");
while ($record = mysql_fetch_assoc($result)):
?>
<ul class="listnav">
<li><a href="http://www.charlotteparent.com/community/blogsnew/archives.php?date_year=<?php echo $record['year'] ?>&date_month=<?php echo $record['month'] ?>"class="blinks"><?php echo $record['dateAndYear']; ?></a></li>
</ul>
<?php endwhile ?>
Here is an example of the page with menu in right sidebar: http://www.charlotteparent.com/community/blogsnew/blogs.php?category=culture%20kid%20reviews
The issue that I am having is figuring out how to list the month and year once at the top of the page next to the word Archives. So, for example if the user clicks on April 2011 and it takes them to the April blog Archives, I want it to say at the top of the page "Archives - April 2011" where it now says Archives in the large green text. I have tried many different options to pull in the month and year but it doesn't work because of this coding I have in place. Can you tell me how I can show the month/year so users can see the archive month at the top of the page?
Thanks!
April
<?php // get list of unique months and years with articles
$query = "SELECT DATE_FORMAT(date, '%M %Y') as dateAndYear, YEAR(date) as year, MONTH(date) as month FROM cms_blogs GROUP BY dateAndYear ORDER BY date DESC";
$result = mysql_query($query) or die("MySQL Error: ". htmlspecialchars(mysql_error()) . "\n");
while ($record = mysql_fetch_assoc($result)):
?>
<ul class="listnav">
<li><a href="http://www.charlotteparent.com/community/blogsnew/archives.php?date_year=<?php echo $record['year'] ?>&date_month=<?php echo $record['month'] ?>"class="blinks"><?php echo $record['dateAndYear']; ?></a></li>
</ul>
<?php endwhile ?>
Here is an example of the page with menu in right sidebar: http://www.charlotteparent.com/community/blogsnew/blogs.php?category=culture%20kid%20reviews
The issue that I am having is figuring out how to list the month and year once at the top of the page next to the word Archives. So, for example if the user clicks on April 2011 and it takes them to the April blog Archives, I want it to say at the top of the page "Archives - April 2011" where it now says Archives in the large green text. I have tried many different options to pull in the month and year but it doesn't work because of this coding I have in place. Can you tell me how I can show the month/year so users can see the archive month at the top of the page?
Thanks!
April
Re: [design9] Blogs Archives
By Jason - May 25, 2011
Hi April,
You can try something like this:
This creates a "date" based on the 2 variables in the string (we use 28 for the "day" since all months will have at least 28 days. This number isn't important, but it helps php decipher which variables are months, days, and years). We then format that date into the form Month Year. You can then output $formattedDate where ever you want.
Hope this helps
You can try something like this:
<?php
$date = @$_REQUEST['date_year']."-".@$_REQUEST['date_month']."-28";
$formattedDate = date("F Y", strtotime($date));
?>
This creates a "date" based on the 2 variables in the string (we use 28 for the "day" since all months will have at least 28 days. This number isn't important, but it helps php decipher which variables are months, days, and years). We then format that date into the form Month Year. You can then output $formattedDate where ever you want.
Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/