• twitter image
  • facebook image
  • youtube image
  • linkedin image
Language: CMS Made Simple Czech CMS Made Simple France CMS Made Simple Spain CMS Made Simple Hungary CMS Made Simple Russia CMS Made Simple Netherlands

All times are UTC




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: I saw somewhere how to find out the number of pages on the website
PostPosted: Tue Dec 14, 2010 5:37 am 
I remember a discussion somewhere on how to find out the number of pages by counting database entries in _content. Can someone help?


Top
  
 
 Post subject: Re: I saw somewhere how to find out the number of pages on the website
PostPosted: Tue Dec 14, 2010 5:38 am 
Offline
Dev Team Member
Dev Team Member
User avatar

Joined: Tue Oct 19, 2004 6:44 pm
Posts: 6586
Location: Fernie British Columbia, Canada
SELECT count(id) FROM _content

_________________
Follow me on twitter
--
if you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
----------------
Don't make me angry..... you won't like me when I'm angry....


Top
 Profile  
 
 Post subject: Re: I saw somewhere how to find out the number of pages on the website
PostPosted: Tue Dec 14, 2010 5:46 am 
Offline
Power Poster
Power Poster
User avatar

Joined: Tue Dec 23, 2008 8:39 pm
Posts: 1320
calguy1000 wrote:
SELECT count(id) FROM _content


SELECT count(content_id) FROM _content

_________________
http://facebook.com/wishbonef1
http://youtube.com/wishbonef1


Top
 Profile  
 
 Post subject: Re: I saw somewhere how to find out the number of pages on the website
PostPosted: Tue Dec 14, 2010 6:10 am 
Why does this produce a blank result if ran from the backend as a UDT?

Code:
   global $gCms;
   $db = $gCms->db;
      
   $query = "SELECT count(content_id) FROM ".cms_db_prefix()."content";
   $dbresult = $db->Execute($query);

   return $dbresult;



Top
  
 
 Post subject: Re: I saw somewhere how to find out the number of pages on the website
PostPosted: Tue Dec 14, 2010 7:28 am 
Offline
Power Poster
Power Poster
User avatar

Joined: Tue Dec 23, 2008 8:39 pm
Posts: 1320
Replace your last line with:

Code:
$row = $dbresult->FetchRow();
return($row['count(content_id)']);


I got 33

_________________
http://facebook.com/wishbonef1
http://youtube.com/wishbonef1


Top
 Profile  
 
 Post subject: Re: I saw somewhere how to find out the number of pages on the website
PostPosted: Tue Dec 14, 2010 11:12 pm 
370  :)


Top
  
 
 Post subject: Re: I saw somewhere how to find out the number of pages on the website
PostPosted: Tue Dec 14, 2010 11:16 pm 
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 "<-add code here to appear in all pages->".

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.


Top
  
 
 Post subject: Re: I saw somewhere how to find out the number of pages on the website
PostPosted: Tue Dec 14, 2010 11:17 pm 
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:
   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)']);


Top
  
 
 Post subject: Re: I saw somewhere how to find out the number of pages on the website
PostPosted: Tue Dec 14, 2010 11:33 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Tue Dec 23, 2008 8:39 pm
Posts: 1320
replytomk3 wrote:
1) What should I add to show only pages that are active?


Code:
$query = "SELECT count(content_id) FROM ".cms_db_prefix()."content WHERE active=1";

_________________
http://facebook.com/wishbonef1
http://youtube.com/wishbonef1


Top
 Profile  
 
 Post subject: Re: I saw somewhere how to find out the number of pages on the website
PostPosted: Tue Dec 14, 2010 11:44 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Tue Dec 23, 2008 8:39 pm
Posts: 1320
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 "<-add code here to appear in all pages->".


Code:
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");
}

_________________
http://facebook.com/wishbonef1
http://youtube.com/wishbonef1


Top
 Profile  
 
 Post subject: Re: I saw somewhere how to find out the number of pages on the website
PostPosted: Tue Dec 14, 2010 11:48 pm 
Offline
Power Poster
Power Poster
User avatar

Joined: Tue Dec 23, 2008 8:39 pm
Posts: 1320
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://facebook.com/wishbonef1
http://youtube.com/wishbonef1


Top
 Profile  
 
 Post subject: Re: I saw somewhere how to find out the number of pages on the website
PostPosted: Wed Dec 15, 2010 2:49 am 
Offline
Power Poster
Power Poster
User avatar

Joined: Tue Dec 23, 2008 8:39 pm
Posts: 1320
Here's a UDT (named 'page_info'), using API calls to get the same info, all at once.

Code:
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:
{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}

_________________
http://facebook.com/wishbonef1
http://youtube.com/wishbonef1


Top
 Profile  
 
 Post subject: Re: I saw somewhere how to find out the number of pages on the website
PostPosted: Wed Dec 15, 2010 3:24 am 
I'm waiting approval on two modules for the Forge. I'll post the code there as a plugin.


Top
  
 
 Post subject: Re: I saw somewhere how to find out the number of pages on the website
PostPosted: Fri Dec 17, 2010 2:11 am 
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:
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);


Top
  
 
 Post subject: Re: I saw somewhere how to find out the number of pages on the website  [SOLVED]
PostPosted: Fri Dec 17, 2010 2:12 am 
How do I also ignore pages that are links?


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Arvixe - A CMSMS Partner