Menu with recursive count of subpages

Submitting your vote...
Rating: 5.0 of 5. 1 vote(s).
Click the rating bar to rate this item.

In my menu I want to display the count of subpages to each page and the count all pages beneath every page.

 

example:

 

root (13/3)

+-page (3/2)

| +-page (1/1)

| | +-page (0/0)

| +-page (0/0)

+-page (6/3)

| +-page (3/2)

| | +-page (0/0)

| | +-page (1/1)

| | +-page (0/0)

| +-page (0/0)

| +-page (0/0)

+-page (1/1)

+-page (0/0)

 

The first number gives the count of all pages beneath

the second number gives the number of direct children

 

 

Solution:

 

This can be done by creating a list of page ids for subpages and their subpages.

In the example below the list of ids for each level is stored in a seperate register value.

 

lib.subcountmenu = COA
lib.subcountmenu {
  10 = HMENU
  10.1 = TMENU
  10.1 {
    expAll = 1
    wrap = <ul>|</ul>
    NO {
      stdWrap.cObject = COA
      stdWrap.cObject {
        				# Here we create a couple register vars which contains a accumulated list of all page ids from each level
        10 = LOAD_REGISTER
        				# 1st we collect the page ids of the current level
        10.level1uids.cObject = COA
        10.level1uids.cObject {
          					# We select the ids of pages that have the id of the current page as parent page.	
          					# Except if the page has the "Hide in menu" checkbox is enabled or the pagetype is
          					# either "Not in menu" (5) or "Backend User Section" (6)
          10 = CONTENT
          10.table = pages
          10.select.pidInList.data = field:uid
          10.select.where = nav_hide!=1 AND doktype!=5 AND doktype!=6
          					# Each page id is rendered with a comma at the end, creating a commaseperated list of page ids
          10.renderObj = TEXT
          10.renderObj.field = uid
          10.renderObj.wrap = |,
          					# Finally we add the id of the current page to the list.
          20 = TEXT
          20.data = field:uid	
        }
        				# For the 2nd level we use the list of page ids we generated for the current level
        10.level2uids.cObject < .10.level1uids.cObject
        10.level2uids.cObject.10.select.pidInList.data = register:level1uids
        				# And finally we add the 1st list of ids to the 2nd list.
        10.level2uids.cObject.20.data = register:level1uids
         
        				# For the 3rd level, we repeat the procedure from the 2nd level.
        				# If your site has more than 3 levels, you should repeat the procedure.
        10.level3uids.cObject < .10.level1uids.cObject
        10.level3uids.cObject.10.select.pidInList.data = register:level2uids
        				# And finally we add the 2st list of ids to the 3rd list.
        10.level3uids.cObject.20.data = register:level2uids
         
        				# Here we count the pages, based on the id lists we created and stored in the register var "level3uids"
        				# Note: If you have created more levels in the LOAD_REGISTER object, you should change "level3uids" to the last level you created.
        20 = TEXT
        20.numRows.table = pages
        20.numRows.select.pidInList.data = register:level3uids
        20.numRows.select.where = nav_hide!=1 AND doktype!=5 AND doktype!=6
        				# And output the page title (Using dataWrap to save some codelines ;) ) along with the count of all pages beneath.
        20.dataWrap = {field:title} [|/
         
        				# Here we count and output the number of direct children.
        30 = TEXT
        30.numRows.table = pages
        30.numRows.select.pidInList.field = uid
        30.numRows.select.where = nav_hide!=1 AND doktype!=5 AND doktype!=6
        30.wrap = |]
      }
      wrapItemAndSub = <li>|</li>
    }
  }
  	# Menulevel 2+3 is just copies of the 1st level.
  10.2 < .10.1
  10.3 < .10.1
}
page.100 < lib.subcountmenu

 

This snippet was submitted by Peter Klein


Top 10 Updates

Using lightbox without extension geändert am  13-Jun-2008 14:20:51
Custom field for GMENU alt text geändert am  13-Jun-2008 13:58:07
Extending typoscript properties with stdWrap geändert am  13-Jun-2008 13:54:32
Create menus using data from other tables than "pages" V2  geändert am  24-Mar-2008 13:02:09
Login geändert am  17-Mar-2008 12:47:52
Forum geändert am  17-Mar-2008 10:07:47
Who is Typo3wizard.com geändert am  26-Dec-2007 16:07:32
Menu as un-nested lists (iphone navigation) geändert am  29-Oct-2007 15:05:53
IF Conditions with AND and OR operators geändert am  16-Oct-2007 19:16:04
UserFunc to fix problems with HMENU type "special=updated"  geändert am  16-Oct-2007 18:58:40
Deutsch
Search: