[Solved] Tag or UDT for total page count?

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am

[Solved] Tag or UDT for total page count?

Post by Cerulean »

Can anyone suggest a core tag or UDT that would give the total number of pages in the website?

Thanks.
Last edited by Cerulean on Wed Oct 30, 2013 8:49 am, edited 1 time in total.
chandra

Re: Tag or UDT for total page count?

Post by chandra »

MenuManager module has a counter for active pages inside which you can use.
Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am

Re: Tag or UDT for total page count?

Post 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.
chandra

Re: Tag or UDT for total page count?

Post 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.
Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am

Re: Tag or UDT for total page count?

Post 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"}
Last edited by Cerulean on Wed Oct 30, 2013 9:00 am, edited 1 time in total.
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

Re: Tag or UDT for total page count?

Post 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}
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
Cerulean
Forum Members
Forum Members
Posts: 172
Joined: Mon Nov 01, 2010 8:56 am

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

Post 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.
User avatar
Rolf
Power Poster
Power Poster
Posts: 7825
Joined: Wed Apr 23, 2008 7:53 am
Contact:

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

Post 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
- + - + - + - + - + - + -
LATEST TUTORIAL AT CMS CAN BE SIMPLE:
Migrating Company Directory module to LISE
- + - + - + - + - + - + -
Image
chandra

Re: Tag or UDT for total page count?

Post 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.
Post Reply

Return to “CMSMS Core”