tags:

views:

16

answers:

2

I have set my monthly Archive page (Archive.php) as like this : Monthly Archive When clicking on any MONTH, the result will show all the posts for that particular month as below:

  • Post title-1 ------ Category-1 ------ Author name
  • Post title-2 ------ Category-1 ------ Author name
  • Post title-3 ------ Category-1 ------ Author name
  • Post title-4 ------ Category-1 ------ Author name
  • Post title-5 ------ Category-1 ------ Author name

But ... I want a display like this :

Category-1

  • Post title-1 ------ Author name Post
  • Post title-2 ------ Author name Post

Category-2

  • Post title-3 ------ Author name Post
  • Post title-4 ------ Author name Post
  • Post title-5 ------ Author name Post
A: 

This would be done when you display your data:

$pCategory = '';
$itemDisplay = '';
foreach ($items as $item) {
    if ($pCategory != $item['category']) {
        $itemDisplay .= '<b>' . $item['category'] . '</b><br><br>';
        $pCategory = $item['category'];
    }
    $itemDisplay .= '    ' . $item['title'] . ' by ' .
                             $item['author'] . '<br>';
}

echo $itemDisplay;

This is of course a rough example. You will have to tailor it to coincide with your code and database structure etc.

Brad F Jacobs
A: 

I am getting this error :

Warning: Invalid argument supplied for foreach()

syed