[HACK] Add a "More..." Sub-Category

Modules, Add-ons and custom code that's more than just a quick hack or Mod.
Post Reply
CharlieFoxtrot
Confirmed
Confirmed
Posts: 413
Joined: Sun Aug 09, 2009 1:23 pm

[HACK] Add a "More..." Sub-Category

Post by CharlieFoxtrot »

InterspireD member Meules had a good idea in this post: http://www.interspired.net/forum/viewto ... f=12&t=229 ... Here's how to do it.

PROBLEM: The default way in which the Side-Category/Subcategory menu is presented can make for some exceedingly long and unwieldy menu displays. This is most noticeable when a Parent Category has many Child Sub-Categories.

GOAL: Allow a pre-defined maximum number of child sub-categories to be displayed... however, if the total number of child sub-categories is greater than our preset limit, then display the word "More..." as a sub-category and skip the rest. The "More..." listing should link to the main product page of the Parent Category so that the customer can see the other sub-categories displayed at the top of the page.

SOLUTION: The steps described below will accomplish this.

As always... MAKE BACKUPS, TEST BEFORE GOING LIVE, etc etc.

VERSION USED HERE: ISC 4.07
FILE TO EDIT: /includes/display/SideCategoryList.php

PLEASE NOTE: I have not included any line numbers here because my version of this file has been bloated with other code and comments... and my line numbers will not match yours. Instead, you'll need to use your editor's search function to carefully locate the exact position for the new code.

================================
STEP 1
================================

FIND:

Code: Select all

$GLOBALS['SubCategoryList'] = $this->GetSubCategory($categories, $rootCat['categoryid']);
JUST ABOVE THAT LINE, ADD:

Code: Select all

// Remember the Parent Category URL for the "More" link
$GLOBALS['ParentCatLinkRecall'] = CatLink($rootCat['categoryid'], $rootCat['catname'], true); 
================================
STEP 2
================================

FIND:

Code: Select all

foreach ($categories[$parentCatId] as $subCat) { 
JUST ABOVE THAT LINE, ADD:

Code: Select all

$maxSubCats=4; // The number of child categories to display (including the "More" link)
================================
STEP 3
================================

FIND:

Code: Select all

if($i == sizeof($categories[$parentCatId])) { 
JUST ABOVE THAT LINE, ADD:

Code: Select all

if($i > $maxSubCats) { continue; } // We have enough. Ignore the rest of the child categories.
if($i == $maxSubCats) { // We've reached the target number. Create the "More..." link.
	$GLOBALS['LastChildClass']='LastChild'; // This is our last sub-category. Set the LastChild CSS style.
	$catName = "More..."; // Let the customer know that there are more sub-categories
	$catLink = $GLOBALS['ParentCatLinkRecall']; // Recall the PARENT category link defined earlier.
} // end if maxSubCats
================================
STEP 4
================================

o Save your work.
o Upload files to your development site.
o Test to make sure it's working.
o When done, upload to your live site... and test again.


================================
STEP 5 (Optional)
================================

Buy me a beer! 8-) PayPal to: charlie.foxtrot[at]foxtrotprinting[dot]com
ISC 4.0.7

"... and let's be honest that whole "by design" thing is getting old too."
meules
Confirmed
Confirmed
Posts: 95
Joined: Wed Jun 17, 2009 8:56 pm
Location: NL

Re: [HACK] Add a "More..." Sub-Category

Post by meules »

Charlie, I've been working on this one all day!! You're the best :mrgreen:

Works perfect with ISC v5.0.6, only thing that is different compared to v.4.0.7:

ISC v.4.0.7

Code: Select all

if($i == sizeof($categories[$parentCatId])) { 
ISC v5.0.6

Code: Select all

if($i == count($categories[$parentCatId])) {
ISC v6
Post Reply