Hide Child Categories in the Sidebar

Creating and modifying plugins.
Post Reply
williamts99
Regular
Posts: 30
Joined: Sat Dec 10, 2005 11:50 pm
Contact:

Hide Child Categories in the Sidebar

Post by williamts99 »

I was wondering, is there a way to hide all of the child categories from showing up when all of the parent categories are displayed. For example, if you have 10 parent categories, and each one has 5 child categories, that would be a lot to show all at once. Is there a way to make it where the child categories will only show up when a parent category is selected? Hopefully it is just a click away and I am just missing where the setting is.

Thanks

Will
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Hide Child Categories in the Sidebar

Post by garvinhicking »

There is a plugin, DHTML category menu which could do that, it's javascript driven and you might want to try it out?

I think in recetn 1.0 versions the categories default plugin has a lot of config options, did you try them all?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
mpfeiffer
Regular
Posts: 17
Joined: Thu Mar 16, 2006 9:19 am

Hide child entries

Post by mpfeiffer »

V 1.0 of the plugin has a lot of options and most of them will help. But one option is missing:

Hide the child categories

similar to

Hide the selected parent category?

If this option could be implemented, it´s perfect (for me).

regards

M.Pfeiffer
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Hide child entries

Post by garvinhicking »

Hi!

Could you describe a bit in detail what you want to achieve? Are you talking about the serendipity_plugin_dhtml_categories plugin?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
mpfeiffer
Regular
Posts: 17
Joined: Thu Mar 16, 2006 9:19 am

Post by mpfeiffer »

No, not the DHTML-Plugin but the Category-Standard-Plugin.

What i ´m meaning is to show only the entries from the actually selected categories and not the content from the child categories

Example:

Test
- Test1
- - Test2

In Test is 1 entry, in Test1 3 entries and in Test2 are 2 entries.

If i select for example categorie test1 i only want to see the 3 entries from Test1 and not the entries from Test2. Today i see in this case 5 entries.

I´ve already checked the sourcecode from the plugin, i think this might not be a big change

Of course i can solve this with the html-nugget, but i like the standard categoroy plugin

regards

M.P.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi!

Ah. This is serendipity core functionality. It has nothing to do with the sidebar plugin. :-)

Can you explain in which case this behaviour is not wanted? Usually people are very fond of the fact how subcategories fold...

It could be patched in the core without too much work, though...

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
mpfeiffer
Regular
Posts: 17
Joined: Thu Mar 16, 2006 9:19 am

Post by mpfeiffer »

If possible you can make as an configurable option for the individuell categories (like hide parent category) or for the whole plugin.

If it is for the whole block, i by myself don´t need exceptions, but others may need this.

regards

M.P.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Uhm, did you get that I said the functionality is totally and completely independent from the sidebar plugin? :)

This would need to be configured in serendipity core, the sidebar plugin couldn't (easily) handle this at all.

Technically it would be very hard to make this functionality only disable for specific categories, because then one additional DB query would need to be performed for every page.

It all boils down to the file include/functions_entries.inc.php, function serendipity_getMultiCategoriesSQL(). You actually would need to replace that whole function with something like this:

Code: Select all

function serendipity_getMultiCategoriesSQL($cats, $invert = false, $no_children = true) {
    global $serendipity;

    $mcategories   = explode(';', $cats);
    $cat_sql_array = array();
    foreach($mcategories AS $categoryid) {
        $categoryid  = (int)$categoryid;

        if ($categoryid != 0) {
            if ($no_children) {
                $cat_sql_array[] = " (c.categoryid " . ($invert ? "!" : "") . " = " . $categoryid . ')';
            } else {
                $cat_sql_array[] = " (c.category_left " . ($invert ? " NOT " : "") . " BETWEEN " . implode(' AND ', serendipity_fetchCategoryRange($categoryid)) . ')';
            }
        }
    }

    return '(' . implode(($invert ? ' AND ' : ' OR '), $cat_sql_array) . ')';
}

If you were to make the behaviour dependant on the parent category, you would:

1. Add a new DB colum "show_parents" to the serendipity_categories table
2. Make the function from above check if "show_parents" of the current category is set to "1" - if yes, set $no_children = false, if not, set it to true.
3. Implement the ability to set the property per category in the "Categories" admin section.

Maybe this could be done with some sub-select or some more advanced AND/ORing to prevent one more DB lookup, but it would still make the query more complex. Disabling to show children categories would be much easier, but if that doesn't help you at all, you might rather want to modify the code manually?

Best regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
mpfeiffer
Regular
Posts: 17
Joined: Thu Mar 16, 2006 9:19 am

Post by mpfeiffer »

Hi Garvin,

thanks for the quick reply. I have changed the code and it works fine.

This kind of solution is absolutely enough for me, i don´t really need this for individuell categories.

best regards

Michael
Post Reply