Page 1 of 1

[Solved] Tag or UDT for total page count?

Posted: Wed Oct 30, 2013 12:09 am
by Cerulean
Can anyone suggest a core tag or UDT that would give the total number of pages in the website?

Thanks.

Re: Tag or UDT for total page count?

Posted: Wed Oct 30, 2013 12:27 am
by chandra
MenuManager module has a counter for active pages inside which you can use.

Re: Tag or UDT for total page count?

Posted: Wed Oct 30, 2013 12:44 am
by Cerulean
Thanks, but can you elaborate a bit?

Do you mean I can create a custom Menu Manager template that would output just the total count of active pages? I don't see a parameter for the {menu} tag that would do this.

Re: Tag or UDT for total page count?

Posted: Wed Oct 30, 2013 7:51 am
by chandra
Ok, my fault - meant Smarty has a total counter for foreach loops ;)

http://www.smarty.net/docs/en/language. ... oreach.tpl
http://www.smarty.net/docs/en/language. ... erty.total

You dont need an additional MenuManager template. It's only the question where you want to output the counter. The variable is everytime available 8).

With this foreach opening in default MenuManager template
{foreach from=$nodelist item=node}
you have only to add
{$node@total}
on the place of output.

Thats all.

Note: node (or something other) must be unique.

Re: Tag or UDT for total page count?

Posted: Wed Oct 30, 2013 8:43 am
by Cerulean
Thanks chandra, works great.

To spell it out...

Create a new Menu Manager template called "page_count":

Code: Select all

{foreach from=$nodelist item=node}
{/foreach}
{$node@total}
In your page template or page:

Code: Select all

Total active pages in menu: {menu template="page_count"}
or

Code: Select all

Total active pages: {menu template="page_count" show_all="1"}

Re: Tag or UDT for total page count?

Posted: Wed Oct 30, 2013 8:53 am
by Rolf
You could try this:
Create a UDT called PageCounter

Code: Select all

$db = cmsms()->GetDb();
		
$query = "SELECT count(content_id) FROM " . cms_db_prefix() . "content WHERE active=1";
$result = $db->Execute($query);

$row = $result->FetchRow();
echo ($row['count(content_id)']);
In the page you add {PageCounter}

Re: [Solved] Tag or UDT for total page count?

Posted: Wed Oct 30, 2013 9:03 am
by Cerulean
Cheers Rolf, that works well too.

I tried your UDT alongside the {menu} solution on one of my sites and the UDT counts 1 extra page, which is interesting. I think the UDT must include pages of the "Error Page" content type in the count whereas the {menu} solution does not.

Re: [Solved] Tag or UDT for total page count?

Posted: Wed Oct 30, 2013 10:42 am
by Rolf
Correct

Code: Select all

$db = cmsms()->GetDb();
		
$query = "SELECT count(content_id) FROM " . cms_db_prefix() . "content WHERE type='content' AND active=1";
$result = $db->Execute($query);

$row = $result->FetchRow();
echo ($row['count(content_id)']);
You could also add/change in line 3

Code: Select all

AND show_in_menu=1

Re: Tag or UDT for total page count?

Posted: Wed Oct 30, 2013 7:54 pm
by chandra
Cerulean wrote: To spell it out...

Create a new Menu Manager template called "page_count":

Code: Select all

{foreach from=$nodelist item=node}
{/foreach}
{$node@total}
If you only have a single menu on your website you dont need an additional MenuManager call.

You can insert

Code: Select all

{$counter = $node@total}
after for the foreach loop inside your current MenuManager template.

With {$counter} you can call now page value where ever you want.

Be aware every additional module call or udt call slows down the performance of your website.