Oh, I just don't believe I am so dense. But there it is in the code; there's no denying it.
YL, I apologize for leading you astray all this time. The problem is simple: I never actually walked the categories, and I never actually used the result anyway. The categories are in $all_cats, while the walking is performed on (and stored in) $categories, which is never populated and never used.
I tested this on Mimbo running in a 1.4.2 sandbox. It works; the   is non-functional in drop-downs, so I did the path/separator thing. Let me know if it works the way you like.
Code: Select all
if ($serendipity['GET']['adminModule'] == 'templates') {
$all_cats = serendipity_fetchCategories('all');
$all_cats = serendipity_walkRecursive($all_cats, 'categoryid', 'parentid', VIEWMODE_THREADED);
$catsel = array();
$fullname = array();
$lastdepth = 0;
foreach($all_cats AS $cat) {
$catdepth = $cat['depth'];
$fullname[$catdepth] = $cat['category_name'];
if ($lastdepth > $catdepth) {
// We've just backed out of a child category; we don't need such a long fullname
$fullname = array_slice($fullname, 0, $catdepth + 1);
}
$lastdepth = $catdepth;
$catsel[$cat['categoryid']] = implode('/', $fullname);
}
}
If you'd rather have a different separator, just change the '/' to ':' or whatever you like.
If you'd rather have an indented version, this works in drop-downs:
Code: Select all
if ($serendipity['GET']['adminModule'] == 'templates') {
$all_cats = serendipity_fetchCategories('all');
$all_cats = serendipity_walkRecursive($all_cats, 'categoryid', 'parentid', VIEWMODE_THREADED);
$catsel = array();
foreach($all_cats AS $cat) {
$catsel[$cat['categoryid']] = str_repeat('-', $cat['depth']) . $cat['category_name'];
}
}
I used a '-' for the repeating character because some browsers render HTML (and HTML escaped characters) in their drop-downs, and others don't. The dash should provide some indentation in all browsers, won't be collapsed by HTML, and will even allow users to count the indentation in most browsers. If you were using this same thing in a sidebar, an ' ' would provide invisible indentation.
Let me know if this works for you.