E
E
Evgeny Elchev2014-06-21 19:42:46
Joomla
Evgeny Elchev, 2014-06-21 19:42:46

Joomla how to get a list of category content?

Hello, I googled a lot on this topic, but I could only find this solution

$db =& JFactory::getDBO();
$query = $db->getQuery(true);
$query = 'SELECT id FROM `#__categories` where parent_id=12';
$db->setQuery($query);
$res= $db->loadAssocList();
$idList=array();
foreach($res as $resOne){
  $idList[]=$resOne['id'];
}
$idList = implode(",", $idList);
$query = 'SELECT * FROM `#__content` WHERE `catid` in (12, '.$idList.') AND `state`>0 LIMIT 0,50';
$db->setQuery($query);
$res= $db->loadObjectList();

Actually, it is used as a draft, but even if you do not find fault with the fact that this is shit code, then it seems to me that there should be another solution based on Api methods.
Tell me, if there are special functions for getting all the materials under the category, or should I not search and just refactor this piece?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2014-06-22
@rsi

Isn't it easier to use the standard Joomla module for these purposes?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question