Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod
- » MetaMod General Support
- » show module on page where another is...
show module on page where another is missing
show module on page where another is missing
This doesn't seem to work in J2.5.
http://www.metamodpro.com/metamod/recip … not-appear
Both modules appear for me, I've double checked
my code:
Code:
$moduleid = 275; /* the module we are checking for. Customise this! */
$sql = 'SELECT count(*) as c from #__modules m, #__modules_menu mm ' .
'WHERE mm.moduleid = m.id ' .
'and m.published = 1 ' .
'and (mm.menuid = ' .
(int)$Itemid . ' or mm.menuid = 0) and mm.moduleid = ' . (int)$moduleid;
$db->setQuery( $sql, 0, 1 );
$row = $db->loadObject();
$not_there = ($row == null or $row->c == 0);
/* replace 101 with module id to display when the other module is not assigned to this page */
if ($not_there) return 216;
Also, how can I change code to allow it to check for multiple IDs and return the one module if none of them are found?
Thanks
[edited by admin: changed jos_ to #__ and added space at end of 2nd line of SQL so it should work now]
Re: show module on page where another is missing
You can check for multiple ids like this. This checks that NONE of the specified modules are assigned to the page. Just change the first two lines to the following:
Code:
$moduleids = "275, 276, 288"; /* the modules we are checking for. Customise this! */
$sql = 'SELECT count(*) as c from #__modules m, #__modules_menu mm ' .
'WHERE mm.moduleid = m.id ' .
'and m.published = 1 ' .
'and (mm.menuid = ' .
(int)$Itemid . ' or mm.menuid = 0) and mm.moduleid in (' . $moduleids . ')';
Or if you want to check that NO modules were assigned to "all" pages or the current page:
Code:
$sql = 'SELECT count(*) as c from #__modules m, #__modules_menu mm ' .
'WHERE mm.moduleid = m.id ' .
'and m.published = 1 ' .
'and (mm.menuid = ' .
(int)$Itemid . ' or mm.menuid = 0)';
Or if you want to check that NO modules were assigned specifically to the current page:
Code:
$sql = 'SELECT count(*) as c from #__modules m, #__modules_menu mm ' .
'WHERE mm.moduleid = m.id ' .
'and m.published = 1 ' .
'and (mm.menuid = ' .
(int)$Itemid;
Hope that helps,
Stephen
[edited by admin: changed jos_ to #__ and added space to 2nd line of SQL in each recipe, so they should work now!]
Re: show module on page where another is missing
thanks. I tried each and while there are no errors, I see 2 modules on the pages where id=216 should not display since the module 275 or 285 is present. This is J2.5 if it makes any difference. Modules 275 and 285 are set to show only on those pages where I see them on top of module 216.
Code:
$moduleids = "275, 285"; /* the modules we are checking for. Customise this! */
$sql = 'SELECT count(*) as c from #__modules m, #__modules_menu mm ' .
'WHERE mm.moduleid = m.id ' .
'and m.published = 1 ' .
'and (mm.menuid = ' .
(int)$Itemid . ' or mm.menuid = 0) and mm.moduleid in (' . $moduleids . ')';
$db->setQuery( $sql, 0, 1 );
$row = $db->loadObject();
$not_there = ($row == null or $row->c == 0);
/* replace 101 with module id to display when the other module is not assigned to this page */
if ($not_there) return 216;
Re: show module on page where another is missing
Hi thepiston,
a few things to check:
1 - basic MetaMod stuff: check that module 216 is set up to display in a non-existant (or "none") module position, or is unpublished, or is set to display on no menu items. Otherwise, it's going to show up by itself even if the MetaMod does not include it. To test this, unpublish the MetaMod and see if 216 is still showing up: if so, you need to disable it in some way.
2 - ensure that you don't have 216 in the "quick module id or position include" box. That's another thing that can make it show up uninvited!
3 - the rules above do not take into account if you have your modules 275 and 285 set up to display on all pages except the ones checked. Is that the way you have 275 and 285 set up? If so, I'll need to rewrite the rules for you.
Thanks,
Stephen
Re: show module on page where another is missing
1-3 are all fine. Module 216 is unpublished and set to "none" position. The metamod works on one of the modules if I just use moduleid=275 or moduleid=285 (one at a time with my original code).
After rereading your answers I think I may have not told you the whole story. I want to display different logos on certain pages. So I want to load module 216 when there is nothing already in that position. The position is "logo".
Re: show module on page where another is missing
Hi again,
I tracked down what I think was the problem, mostly to do with the forum software I use... all the #__ were being changed to jos_ when you submit a post to the forum, and in J2.5, jos_ is no longer the prefix. So that was messing it all up. Also, the 2nd line of SQL in each recipe needed a trailing space before the final quote. I have now fixed this in all the posts in this thread, so please go back to them and the examples should work this time!
Sorry for the hassles,
Stephen
- Index
- » MetaMod
- » MetaMod General Support
- » show module on page where another is...
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5942
- Total Posts Today:
- 1
- User Info:
- Total Users:
- 7623
- Newest User:
- laptopreviews21
- Members Online:
- 0
- Guests Online:
- 126
- 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