Page 1 of 1

Take the number of news

Posted: Fri Sep 15, 2006 3:07 pm
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!

Re: Take the number of news

Posted: Sat Sep 16, 2006 1:00 am
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.

Re: Take the number of news

Posted: Sat Sep 16, 2006 8:11 am
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);

}

?>

Re: Take the number of news

Posted: Mon Sep 18, 2006 7:22 am
by aleix
It works fine Piratos, thanks a lot!