[TYPO3-news] [TYPO3-project-news] Re: count news associated with a particular category
sonal vadhavana
sonal.nitsan at gmail.com
Sun Jan 8 13:27:48 CET 2017
Quote: giulio zulian (giuliopallino) wrote on Tue, 02 February 2016 17:39
----------------------------------------------------
> Good evening, how I count the number of news associated with a particular category?
>
>
> thanks
----------------------------------------------------
Hello here is the solution for that.
Need to follow the below steps for that.
1) Pass the category id by one typoscript object.
<f:cObject typoscriptObjectPath="lib.countCat">{category.item.uid}</f:cObject>
2) That passed category id will sent to userfunc and the userfnction will procee to count the news.
lib.temp = TEXT
lib.temp {
current = 1
}
lib.countCat = USER
lib.countCat {
includeLibs = fileadmin/user_misc.php
userFunc = user_misc->countCat
value < lib.temp
}
3) The code for userfunc file is here.
<?php
class user_misc {
public $cObj;
public function countCat ($content, $conf){
$pageId = $this->cObj->TEXT($conf);
$con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("demo_7612", $con);
$query = "SELECT * FROM `sys_category_record_mm` WHERE `uid_local` =$pageId LIMIT 0 , 30";
$comments = mysql_query($query);
$count = 0;
while($row = mysql_fetch_array($comments, MYSQL_ASSOC))
{
$count = $count + 1;
}
return $count;
mysql_close($con);
}
}
?>
More information about the TYPO3-project-news
mailing list