ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Issue with exp:weblog:categories and show_empty where a category group is shared

August 03, 2011 7:45am

Subscribe [2]
  • #1 / Aug 03, 2011 7:45am

    Paul Bell

    104 posts

    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 = 3

    This 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.

  • #2 / Aug 03, 2011 6:06pm

    Dan Decker

    7338 posts

    Hi Paul,

    The current version of ExpressionEngine 1 is 1.7.1 and may address the issues you outline here. I know updating might not be an option for you. I’m glad you were able to solve your issue.

    Cheers!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases