Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod Pro
- » MetaMod Pro General Support
- » show module only if more than one...
show module only if more than one article is related to a category
show module only if more than one article is related to a category
hi,
i tried to find out if it is possible to show the related articles module only if more than one article is assigned to the actual category. I´ve been not successful. Maybe someone out there is able to help me?
Kind Regards
Re: show module only if more than one article is related to a category
Can you just confirm what version of Joomla you are using?
If on J2.5, the following should work I think:
$catid = $content_genius("category_id");
if ($catid == '') return; // don't continue if we don't have a cat id
$db->query("select count(*) from #_" . "_content where catid = " . (int)$catid);
$count = $db->loadResult();
if ($count > 1) return XXX;
// replace XXX with the id of the module to use if there's more than
// one article in the current category.
Re: show module only if more than one article is related to a category
Hi Stephen,
thank you for the quick answer. I´m using Joomla 2.5 and MetaMod Pro for our internal info-website. Yesterday I tried hard to remeber all the php stuff I recently knew. Finallay (with your help!) it worked with a little modification:
Code:
if ($option == 'com_content' and $view == 'article')
{
$db->setQuery('SELECT catid FROM #_"."_content WHERE id='.$id);
$category_id = $db->loadResult();
$db->setQuery('SELECT count(id) FROM #_"."_content WHERE state=1 and catid='.$category_id);
$count = $db->loadResult();
if ($count > 2) return 69;
}
It seems that the $content_genius variable is not accessable. Do I need Chameleon or something else to use it?
Anyway, maybe not the most beautiful code, but it works. If you have any improvements, please let me know ;-)
Thanks a lot, a really great module!
Jens
Re: show module only if more than one article is related to a category
weird that content_genius was not available... it should be... but you have generally the right idea about how to get hold of the ID.
The only MAJOR MAJOR MAJOR problem in your code is that you are not escaping the $id, so this is a SQL injection alert. If you simply cast it to an int then you'll be fine:
$db->setQuery('SELECT catid FROM #_"."_content WHERE id='.(int)$id);
Cheers,
Stephen
Re: show module only if more than one article is related to a category
Actually, looking at this again there are several problems with it.
Try this:
if ($option == 'com_content' and $view == 'article')
{
$db->setQuery('SELECT catid FROM #_'.'_content WHERE id=' . (int)$id);
$category_id = $db->loadResult();
$db->setQuery('SELECT count(id) FROM #_'.'_content WHERE state=1 and catid=' . (int)$category_id);
$count = $db->loadResult();
if ($count > 2) return 69;
}
- Index
- » MetaMod Pro
- » MetaMod Pro General Support
- » show module only if more than one...
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5943
- Total Posts Today:
- 1
- User Info:
- Total Users:
- 7638
- Newest User:
- moner86658
- Members Online:
- 0
- Guests Online:
- 119
- Online:
- There are no members online
Forum Legend:
Topic
New
Locked
Sticky
Active
New/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky/Active/Locked