Forum
Blog Archive by Categories Not Returning Anything
Up until recently I'd been using categories in the admin area but never using them on the front end of my site. I'm changing things around a bit now and want to use categories for people to filter my posts.
I've updated the blog and following a few issues I can now see the checkboxes in the admin area and the posts seem to be assigned but I cannot get the archive.php to return anything.
This is the code I have at present…
<?php
// defaults for all modes
$posts_per_page = 10;
$template = 'post_in_list.html';
$sort_order = 'DESC';
$sort_by = 'postDateTime';
// Have we displayed any posts yet?
$posts_displayed = false;
/*
perch_get() is used to get options from the URL.
e.g. for the URL
/blog/archive.php?cat=news
perch_get('cat') would return 'news' because cat=news.
The code below looks for different options in the URL, and then displays different types of listings based on it.
*/
/* --------------------------- POSTS BY CATEGORY --------------------------- */
if (perch_get('cat')) {
echo '<h1>Archive of: '.perch_blog_category(perch_get('cat'), true).'</h1>';
perch_blog_custom(array(
'category' => perch_get('cat'),
'template' => $template,
'count' => $posts_per_page,
'sort' => $sort_by,
'sort-order' => $sort_order,
));
$posts_displayed = true;
}
/* --------------------------- DEFAULT: ALL POSTS --------------------------- */
if ($posts_displayed == false) {
// No other options have been used; no posts have been displayed yet.
// So display all posts.
echo '<h1>Archive</h1>';
perch_blog_custom(array(
'template' => $template,
'count' => $posts_per_page,
'sort' => $sort_by,
'sort-order' => $sort_order,
));
}
?>
Which is taken from the example files. Visiting the URL /archive.php?cat=design returns nothing. If I drop out the first if statement all the content shows but obviously it's not filtered.
Any pointers? I'm not sure what step to take next.
Thanks
If you turn on debug, what does it output?
Nothing on the archive page at all
Can you see the closing
</html>
tag?Yeah the closing </html> tag is there
And you're outputting the debug below that point?
I wasn't actually, am now - here's the debug…
It doesn't look like there are posts in that category. Are there?
Damn! Yes there are but it looks like they all need re-saving - cheers for the help Drew!