#26 Use of $children in list_cats

open
nobody
None
5
2004-06-07
2004-06-07
ophois
No

Please excuse me if this is the intended operation but.

The wiki states that the list_cats children perameter
should indicate whether the children of a catagory are
shown. In practice however it controls whether a flat
list of catagories is shown or a hierarchical one. This
appears to be due to an if statement in the code.

context:

function list_cats(....

foreach ($categories as $category) {
if ((intval($hide_empty) == 0 || isset
($category_posts["$category->cat_ID"])) && (!$children
|| $category->category_parent == $child_of)) {

...

if ($children) $thelist .= list_cats
($optionall, $all, $sort_column, $sort_order, $file, $list,
$optiondates, $optioncount, $hide_empty,
$use_desc_for_title, $children, $category->cat_ID,
$categories, 1, $feed, $feed_image, $exclude);

...

The first if statement controls the display of a
catagory. In this case the logic states that if children is
not set then the catagory will be displayed however the
list $categories contains all catagroies, even those
which are not children of $child_of. If $children is set to
TRUE(1) then it will only show those categores with the
supplied parent (0 by default hence only top level
categories I assume), however the second If will then
execute and you will get the children displayed anyway.

The $children param simply controls where they are
displayed. As such I would suggest (and feel free to
shout me down if Im being thick) that the param is
renamed (flatten_list_before_sort would seem
appropriate), or more usefully the functionality is fixed to
follow the wiki documentation.

A suggested fix would be to simplty ammend the first if
to:

if ((intval($hide_empty) == 0 || isset($category_posts
["$category->cat_ID"])) && ($category-
>category_parent == $child_of)) {

This will only result in the selected level being printed by
this itteration, but the function will still recurse down if
$children is set to true.

Ophois
Andrew Milne

Discussion


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks