Trying to modify a function.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gtowle
Forum Newbie
Posts: 2
Joined: Wed Jun 13, 2007 2:11 pm
Location: Santa Fe, NM

Trying to modify a function.

Post by gtowle »

I'm trying -unsuccessfully so far- to modify this function so that only the parent link shows in the navigation, rather than the parent AND the current page (as it now does).

Can someone offer some help? Thanks.

Code: Select all

function getCategoriesNavLine($parent=0, &$tree){
		$l = $tree->collection[$parent]->level;
		$pa = $tree->collection[$parent];
		$nav = "";
		for($i = $l; $i >= 1; $i--){
			if(($i==0) || ($i>$l-4)){
				$nav = '/ <a href="'.getCatalogUrl($pa->caption, $pa->id, 1).'">'.gs($pa->caption).'</a> '.($i<>$l?"":"").$nav;
			}
			else{
				$nav = '.. / '.$nav;
			}
			if($i>0){
				$pa = $tree->collection[$pa->parent_id];
			}
		}
		return $nav;
	}
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

from what I see it shows:

Code: Select all

/root/../grandgrandparent/grandparent/parent/item
which one would you like to get rid of?
User avatar
gtowle
Forum Newbie
Posts: 2
Joined: Wed Jun 13, 2007 2:11 pm
Location: Santa Fe, NM

Post by gtowle »

Weirdan-

How do you interpret that???

I want to get rid of item, I believe (assuming that would be the "current" page ("page" for lack of better term).

Thanks.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

function getCategoriesNavLineWithoutCurrentItem($parent=0, &$tree){
                $parent = $tree->collection[$parent]->parent_id; // <==== 
                $l = $tree->collection[$parent]->level;
                $pa = $tree->collection[$parent];
                $nav = "";
                for($i = $l; $i >= 1; $i--){
                        if(($i==0) || ($i>$l-4)){
                                $nav = '/ <a href="'.getCatalogUrl($pa->caption, $pa->id, 1).'">'.gs($pa->caption).'</a> '.($i<>$l?"":"").$nav;
                        }
                        else{
                                $nav = '.. / '.$nav;
                        }
                        if($i>0){
                                $pa = $tree->collection[$pa->parent_id];
                        }
                }
                return $nav;
        }
Post Reply