Blog

2 posts by 2 authors in: Forums > CMS Builder
Last Post: September 25, 2014   (RSS)

Hi Guys,

Is there a simple way of doing this?  I'm ending up with millions of lines of code.

I have a section "blog" with the following fields;

Title (text field)
Category (multi-select list)
Date (date field)
Content (wysiwyg)

I want to publish a blog page, that groups records by month, or by category.  It displays links to all months and all categories, and displays the currently selected group or defaults to current month if nothing selected. ie.

<div id="navigation">
<nav id="months">
<!-- group articles by month" -->
<a>Month</a>
<a>Month</a>
<a>Month</a>
</nav>

<nav id="category">
<!-- group articles by month" -->
<a>Category</a>
<a>Category</a>
<a>Category</a>
</nav>
</div>


<!-- Display the selected month or category -->
<h1>Selected Group</h1>

<!-- list articles within current group" -->
<div>
<h2>Article 1</h2>
<p>This is the blog content</p>
</div>

<div>
<h2>Article 2</h2>
<p>This is the blog content</p>
</div>

<div>
<h2>Article 3</h2>
<p>This is the blog content</p>
</div>

I'm currently using the code below to group dates - but think there would be a better option?

<?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_blog 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)):
?>

Cheers,

Tim (toledoh.com.au)