Page 1 of 2

I saw somewhere how to find out the number of pages on the website

Posted: Tue Dec 14, 2010 5:37 am
by replytomk3
I remember a discussion somewhere on how to find out the number of pages by counting database entries in _content. Can someone help?

Re: I saw somewhere how to find out the number of pages on the website

Posted: Tue Dec 14, 2010 5:38 am
by calguy1000
SELECT count(id) FROM _content

Re: I saw somewhere how to find out the number of pages on the website

Posted: Tue Dec 14, 2010 5:46 am
by Wishbone
calguy1000 wrote: SELECT count(id) FROM _content
SELECT count(content_id) FROM _content

Re: I saw somewhere how to find out the number of pages on the website

Posted: Tue Dec 14, 2010 6:10 am
by replytomk3
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

Posted: Tue Dec 14, 2010 7:28 am
by Wishbone
Replace your last line with:

Code: Select all

$row = $dbresult->FetchRow();
return($row['count(content_id)']);
I got 33

Re: I saw somewhere how to find out the number of pages on the website

Posted: Tue Dec 14, 2010 11:12 pm
by replytomk3
370  :)

Re: I saw somewhere how to find out the number of pages on the website

Posted: Tue Dec 14, 2010 11:16 pm
by replytomk3
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.

Re: I saw somewhere how to find out the number of pages on the website

Posted: Tue Dec 14, 2010 11:17 pm
by replytomk3
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

Posted: Tue Dec 14, 2010 11:33 pm
by Wishbone
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

Posted: Tue Dec 14, 2010 11:44 pm
by Wishbone
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

Posted: Tue Dec 14, 2010 11:48 pm
by Wishbone
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.

Re: I saw somewhere how to find out the number of pages on the website

Posted: Wed Dec 15, 2010 2:49 am
by Wishbone
Here's a UDT (named 'page_info'), using API calls to get the same info, all at once.

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);
Here's how to use it in your template or page:

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}

Re: I saw somewhere how to find out the number of pages on the website

Posted: Wed Dec 15, 2010 3:24 am
by replytomk3
I'm waiting approval on two modules for the Forge. I'll post the code there as a plugin.

Re: I saw somewhere how to find out the number of pages on the website

Posted: Fri Dec 17, 2010 2:11 am
by replytomk3
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).

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);

Re: I saw somewhere how to find out the number of pages on the website

Posted: Fri Dec 17, 2010 2:12 am
by replytomk3
How do I also ignore pages that are links?