Gossamer Forum
Home : Products : Gossamer Links : PHP Front End :

Re: [Dan Kaplan] showing 'father' category in related@ links

Quote Reply
Re: [Dan Kaplan] showing 'father' category in related@ links In reply to
Ok, I think part 2 is now functional enough. Here's a good example page:

http://run-down.com/.../index.php?cat_id=11

It seems a bit slower as a result of the extra sorting, but not too bad.

In Page.inc.php's generate_category_page(), I changed:

Code:
while ($cat = $sth->fetchrow_hash()) {
if (isset($rel[$cat['ID']])) {
$cat['Related'] = 1;
$cat['RelationName'] = $rel[$cat['ID']];
}
$display['category_loop'][] = $cat;
}

to:

Code:
while ($cat = $sth->fetchrow_hash()) {
if (isset($rel[$cat['ID']])) {
$cat['Related'] = 1;
$cat['RelationName'] = $rel[$cat['ID']];
$this_sort = $cat['Full_Name'];
} else {
$this_sort = $cat['Name'];
}
$cat['sort_by'] = $this_sort;

$display['category_loop'][] = $cat;
}

and in Util.inc.php's _print_cat(), I added:

Code:
if (sizeof($sub_cat) > 1) {
$sort_array = array ();
foreach ($sub_cat as $this_cat) {
$sort_array[] = $this_cat['sort_by'];
}
array_multisort ($sort_array, $sub_cat, SORT_ASC, SORT_STRING);
}

after:

Code:
$parent_cat = array_shift($sub_cat);

Basically, what I did was to use the normal Name field for regular categories and Full_Name field for related categories, but combined into one sort for an overall alphabetical list.

The only way I could figure to then get the overall array of categories into order was to build a second multi-dimensional array ($sort_array) that contained just the combined sort titles with the same key associations, then run it through array_multisort() along with $sub_cat.

If anyone can think of a cleaner or more efficient way to do it, I'm all ears!

Dan
Subject Author Views Date
Thread showing 'father' category in related@ links Dan Kaplan 4034 Jul 3, 2002, 11:38 AM
Thread Re: [Dan Kaplan] showing 'father' category in related@ links
Dan Kaplan 3961 Jul 3, 2002, 12:59 PM
Post Re: [Dan Kaplan] showing 'father' category in related@ links
Dan Kaplan 3948 Jul 3, 2002, 3:37 PM
Thread Re: [Dan Kaplan] showing 'father' category in related@ links
brewt 3950 Jul 4, 2002, 12:17 AM
Post Re: [brewt] showing 'father' category in related@ links
Dan Kaplan 3944 Jul 4, 2002, 8:28 AM
Thread Re: [Dan Kaplan] showing 'father' category in related@ links
Dan Kaplan 3891 Aug 12, 2002, 10:44 AM
Post Re: [Dan Kaplan] showing 'father' category in related@ links
Dan Kaplan 3863 Aug 12, 2002, 10:40 PM