Hello, I have the following tag:
{exp:weblog:categories weblog="accessories" show_empty="no" parent_only="yes" category_group="16" }Category group 16 is shared with another weblog, “garments”. I don’t want it to show me empty categories, but I want that to be specific to the weblog I’ve selected. At the moment, what I get is all the categories that have something in them, but it’s including those categories that only have entries in the “garments” weblog, which isn’t what I’d expect.
If you look at the queries being run, the “weblog” parameter only chooses the appropriate category groups, but then show_empty doesn’t reflect the weblogs at all.
It would be easy enough to do this by adding a line to the query that gets the category IDs (and that’s what I’ve done with this bit of PHP:
<?php
global $DB;
// Do this query ourselves, to get only those categories that have accessories.
$sql = "SELECT DISTINCT(exp_categories.cat_id), parent_id
FROM exp_categories
LEFT JOIN exp_category_posts ON exp_categories.cat_id = exp_category_posts.cat_id
LEFT JOIN exp_weblog_titles ON exp_category_posts.entry_id = exp_weblog_titles.entry_id
WHERE group_id IN ('16') AND exp_weblog_titles.site_id IN ('1')
AND exp_category_posts.cat_id IS NOT NULL
AND exp_weblog_titles.status != 'closed'
AND exp_weblog_titles.entry_date < ".mktime()."
AND (exp_weblog_titles.expiration_date = 0 OR exp_weblog_titles.expiration_date > ".mktime().") AND parent_id = 0
AND exp_weblog_titles.weblog_id = 3
ORDER BY group_id, parent_id, cat_order";
$query = $DB->query($sql);
if ($query->num_rows > 0)
{
foreach($query->result as $row)
{
$designers[] = $row['cat_id'];
}
}
?>The extra line I’ve added is here:
AND exp_weblog_titles.weblog_id = 3This gets me the category IDs I want. I can then make the weblog categories tag do what I want it to by adding
show="<?php echo implode('|',$designers) ?>"but for me, this should be how it works by default. Perhaps this is a bug report? If so, feel free to move. Don’t know if this affects EE2 either, but I suspect it might. I’m on EE1.6.8.