I saw somewhere how to find out the number of pages on the website
- 
				replytomk3
 
I saw somewhere how to find out the number of pages on the website
I remember a discussion somewhere on how to find out the number of pages by counting database entries in _content. Can someone help?
			
			
									
						
										
						- 
				calguy1000
 - Support Guru

 - Posts: 8169
 - Joined: Tue Oct 19, 2004 6:44 pm
 
Re: I saw somewhere how to find out the number of pages on the website
SELECT count(id) FROM _content
			
			
									
						
							Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
			
						Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Re: I saw somewhere how to find out the number of pages on the website
SELECT count(content_id) FROM _contentcalguy1000 wrote: SELECT count(id) FROM _content
- 
				replytomk3
 
Re: I saw somewhere how to find out the number of pages on the website
Why does this produce a blank result if ran from the backend as a UDT?
			
			
									
						
										
						Code: Select all
	global $gCms;
	$db = $gCms->db;
		
	$query = "SELECT count(content_id) FROM ".cms_db_prefix()."content";
	$dbresult = $db->Execute($query);
	return $dbresult;
Re: I saw somewhere how to find out the number of pages on the website
Replace your last line with:
I got 33
			
			
									
						
										
						Code: Select all
$row = $dbresult->FetchRow();
return($row['count(content_id)']);- 
				replytomk3
 
Re: I saw somewhere how to find out the number of pages on the website
OK, I would like to release this code for the benefit of others.
1) What should I add to show only pages that are active?
2) For you experts, what would the code be to return a list of pages with empty (missing) metadata content in the database, or if it contains the default "".
I have already released something based on "last modified pages": http://dev.cmsmadesimple.org/projects/lastcreatedpage. These features should help those who have not specified metadata when they should have.
			
			
									
						
										
						1) What should I add to show only pages that are active?
2) For you experts, what would the code be to return a list of pages with empty (missing) metadata content in the database, or if it contains the default "".
I have already released something based on "last modified pages": http://dev.cmsmadesimple.org/projects/lastcreatedpage. These features should help those who have not specified metadata when they should have.
- 
				replytomk3
 
Re: I saw somewhere how to find out the number of pages on the website
For the benefit of others, the code that you can run as a UDT to find out the number of pages you have (including hidden and inactive) is:
			
			
									
						
										
						Code: Select all
	global $gCms;
	$db = $gCms->db;
		
	$query = "SELECT count(content_id) FROM ".cms_db_prefix()."content";
	$dbresult = $db->Execute($query);
	$row = $dbresult->FetchRow();
        return($row['count(content_id)']);Re: I saw somewhere how to find out the number of pages on the website
replytomk3 wrote: 1) What should I add to show only pages that are active?
Code: Select all
$query = "SELECT count(content_id) FROM ".cms_db_prefix()."content WHERE active=1";Re: I saw somewhere how to find out the number of pages on the website
replytomk3 wrote: 2) For you experts, what would the code be to return a list of pages with empty (missing) metadata content in the database, or if it contains the default "".
Code: Select all
global $gCms;
$db = $gCms->db;
		
$query = "SELECT content_name FROM ".cms_db_prefix()."content WHERE metadata='' OR metadata LIKE '%Add code here%'";
$dbresult = $db->Execute($query);
while ($dbresult && $row = $dbresult->FetchRow()) {
  echo("<p>$row['content_name']<p>\n");
}Re: I saw somewhere how to find out the number of pages on the website
We might even make it simpler by using a call or two from the ContentOperations class.
http://www.cmsmadesimple.org/apidoc/CMS ... tions.html
I'll look at it tonight when I have a bit more time.
			
			
									
						
										
						http://www.cmsmadesimple.org/apidoc/CMS ... tions.html
I'll look at it tonight when I have a bit more time.
Re: I saw somewhere how to find out the number of pages on the website
Here's a UDT (named 'page_info'), using API calls to get the same info, all at once.
Here's how to use it in your template or page:
			
			
									
						
										
						Code: Select all
global $gCms;
$cntnt = $gCms->getContentOperations();
$results['page_count'] = 0;
foreach ($cntnt->GetAllContent() as $page) {
  if ($page->mActive) {
    $results['page_count']++;
  }
  if (!$page->mMetadata || preg_match('/Add code here/', $page->mMetadata)) {
    $results['no_metadata'] .= $page->mName . ' ';
  }
}
$smarty->assign($params['assign'], $results);Code: Select all
{page_info assign='info'}
<p>Number of active pages: {$info.page_count}</p>
{if $info.no_metadata}
<p>The following pages are missing metadata: {$info.no_metadata}</p>
{else}
<p>All pages have metadata</p>
{/if}
- 
				replytomk3
 
Re: I saw somewhere how to find out the number of pages on the website
I'm waiting approval on two modules for the Forge. I'll post the code there as a plugin.
			
			
									
						
										
						- 
				replytomk3
 
Re: I saw somewhere how to find out the number of pages on the website
You are doing all the work.
I have modified it to be on separate lines, and to not show inactive pages (those for me are pages in progress, I don't know about others. Anyways, if you cannot navigate to them, I don't care about metadata for those pages).
			
			
									
						
										
						I have modified it to be on separate lines, and to not show inactive pages (those for me are pages in progress, I don't know about others. Anyways, if you cannot navigate to them, I don't care about metadata for those pages).
Code: Select all
global $gCms;
$cntnt = $gCms->getContentOperations();
$results['page_count'] = 0;
foreach ($cntnt->GetAllContent() as $page) {
  if ($page->mActive) {
    $results['page_count']++;
  }
  if (($page->mActive && !$page->mMetadata) || preg_match('/Add code here/', $page->mMetadata)) {
    $results['no_metadata'] .=  ' <p>' . $page->mName;
  }
}
$smarty->assign($params['assign'], $results);- 
				replytomk3
 
Re: I saw somewhere how to find out the number of pages on the website
How do I also ignore pages that are links?
			
			
									
						
										
						
