Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

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

quarkdash
Beginner Modder
ranks
useravatar
Offline
3 Posts
Administrator has disabled public posting

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.

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3312 Posts
User info in posts
Administrator has disabled public posting

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

quarkdash
Beginner Modder
ranks
useravatar
Offline
3 Posts
Administrator has disabled public posting

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

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3312 Posts
User info in posts
Administrator has disabled public posting

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;
}

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3312 Posts
User info in posts
Administrator has disabled public posting

Re: show module only if more than one article is related to a category

Hi Stephen,

I changed the code - works as it should.

Thanks for your support.
Jens

quarkdash
Beginner Modder
ranks
useravatar
Offline
3 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1667
Total Polls:
6
Total Posts:
5909
Total Posts Today:
1
User Info:
 
Total Users:
10075
Newest User:
rsker57
Members Online:
0
Guests Online:
235

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