Take the number of news

General project discussion. NOT for help questions.
Post Reply
aleix

Take the number of news

Post by aleix »

Hi everybody, I would like to know if there is a way to know the number of news that will be shown into the module.

In need to know this value from a user defined tag because depending on this number I will show another page or not.

Could anyone help me??

Thanks!
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Take the number of news

Post by Dr.CSS »

Not sure what "number of news that will be shown into the module" means but the News module in admin will show all news articles.

If you mean on the page you put the News tag than it will show all the news articles unless you tell it how many... {cms_modules module='news' number='4'} will only show the latest 4 news articles category='general' will just show the articles under the general category, you can make your own categories.

If you go to Extesions>Modules> you will see the name of the modules and to the right is the word Help if you click Help you will see the parameters it uses.
Piratos

Re: Take the number of news

Post by Piratos »

You need this small plugin.

Copy it in the plugins folder as function.cms_newscount.php and set it in the page you want {cms_newscount}

It returns the number of valid news of all.

It works with 0.13 and 1.01.

Code: Select all

<?php

function smarty_cms_function_cms_newscount($params, &$smarty)
{
  global $gCms,$CMS_SCHEMA_VERSION;;
  $db =& $gCms->GetDb();
  if ($CMS_SCHEMA_VERSION >"19")
  {
    $dtime = $db->DBTimeStamp(time());
    $d_one = $db->DBTimeStamp(1);
  }
  else
  {
    $dtime ="'".$db->DBTimeStamp(time())."'";
    $d_one ="'".$db->DBTimeStamp(1)."'";
  }
  $sql = "SELECT news_id, start_time, end_time,news_date,status FROM " . cms_db_prefix() . "module_news  WHERE status = 'published' AND ";
		$sql .= "(".$db->IfNull('start_time',$d_one)." < ".$dtime.")";
		$sql .= " AND ((".$db->IfNull('end_time',$d_one)." = ".$d_one.") OR (end_time > ".$dtime."))";
  $dbresult = $db->GetArray($sql);
  if (!$dbresult) return 0; else return count($dbresult);

}

?>
aleix

Re: Take the number of news

Post by aleix »

It works fine Piratos, thanks a lot!
Post Reply

Return to “General Discussion”