Jump to content


Photo

Defining How Many Levels Deep Current Page Is


  • Please log in to reply
2 replies to this topic

#1 vampke

vampke

    Likes Etomite Forums!

  • Member
  • PipPip
  • 174 posts

Posted 30 November 2011 - 09:06 PM

Hi guys,

It's been a while since I've been in. Hope everybody's doing ok :)

I need to find out how many levels deep a certain page is. How can you do this in a snippet?

Let's say the sites setup is something like:
Home
Products
|_category1
___ |_product1
___|_product2
|_category2
___|_product3
___|_product4
|_category3
___|_product5
.....

How can I use a single snippet that will return 1 when run from category1.html and 2 from product1.html ?
Looks easy enough, but I have been struggling with this for over an hour....

Edited by vampke, 30 November 2011 - 09:07 PM.


#2 vampke

vampke

    Likes Etomite Forums!

  • Member
  • PipPip
  • 174 posts

Posted 01 December 2011 - 09:05 AM

Got it!
With help from the breadcrumb snippet:
  // get current page parent id
  $docInfo = $etomite->getDocument($etomite->documentIdentifier);
  $pid = $docInfo['parent'];

  $levelsDeep = 0;
  while (($parent=$etomite->getPageInfo($pid,0,"parent"))) {
	$pid = $parent['parent'];
	$levelsDeep ++;
  }
return $levelsDeep;

Edited by vampke, 01 December 2011 - 09:06 AM.


#3 Ralph

Ralph

    Loves Etomite Forums!

  • Admin
  • 6,539 posts

Posted 01 December 2011 - 10:20 PM

Glad you got it figured out, Vampke... I read your post last night but wasn't in a position to post a reply, let alone a working example... Reverse calculating back to parent == 0 or parent == $etomite->config['site_start'] is the way to go... The second option would be useful if your site starts within a folder in the document tree...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users