Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod
- » MetaMod General Support
- » Modules by sectionid not working as...
Modules by sectionid not working as expected
Modules by sectionid not working as expected
Hi Folks, firstly amazing mod. Two things why isn't it more visible in the joomla extensions directory (i think its been overlooked!) and secondly how come Joomla havn't thought of this kind of mod for the core? I've been keeping a close eye on 1.6 and its miles off what this can control. Good stuff
Right now my problem.
Im running joomla 1.5.14 and I download metamod free couple of days ago so it should be the latest j version i believe.
Ok I used the 'control modules based on article section' This is my code.
Code:
$section_id = null;
if ( $option == "com_content" ) {
if ( $view == "section" ) {
/* section list pages (blog or list style) */
$section_id = (int)$id;
} else if (array_key_exists("sectionid",$_REQUEST)) {
/* if the section id is in the URL */
$section_id = (int)JRequest::getInt("sectionid",0);
}
if ( $section_id === null && $view == "article" ) {
/* if it's an article page without the sectionid mentioned in the url */
$nullDate = $db->Quote($db->getNullDate());
$my_id = $db->getEscaped((int)$id);
$query = "SELECT title, id, catid "
. " FROM jos_content WHERE id = '$my_id' AND state = 1"
. " AND ( publish_up = " . $nullDate
. " OR publish_up <= CURRENT_TIMESTAMP )"
. " AND ( publish_down = " . $nullDate
. " OR publish_down >= CURRENT_TIMESTAMP )";
$db->setQuery( $query, 0, 1 );
$row = $db->loadObject();
$section_id = $row->sectionid;
}
}
/* Now customise any of the following rules for your use.
* $section_id will correspond to the section id of the
* article being displayed (if one is being displayed!)
*/
if ($section_id == 1) return 58;
if ($section_id == 2) return 57;
if ($section_id == 3) return 60;
if ($section_id == 4) return 56;
if ($section_id == 5) return 59;
Unfourtunately it only appears on section blog layouts. Not much good to me when I want it to appear on every article in the section. In the receipe page most of a section is red
Code:
$query = "SELECT title, id, catid "
. " FROM jos_content WHERE id = '$my_id' AND state = 1"
. " AND ( publish_up = " . $nullDate
. " OR publish_up <= CURRENT_TIMESTAMP )"
. " AND ( publish_down = " . $nullDate
. " OR publish_down >= CURRENT_TIMESTAMP )";
I changed the #__content to jos_content to reflect my database name prefix. But the rest I don't know if I should change or not.
What have i done wrong here then?
Thank you very much in advance.
Regards,
Ty
Re: Modules by sectionid not working as expected
Hi Ty,
thanks for your e-mail and your nice comments about MetaMod. Like you, I find it hard to believe that the main Joomla devs don't "get it" when it comes to smart module placement. I can't even get a patch into Joomla 1.6 to give modules start and stop times like articles have! But then, you have to remember that there are literally hundreds of other issues that are important to address, some of them really big, and they have to prioritise what goes into the core of Joomla. At least there's the JED, where people can go to find really great stuff. The 3rd-party scene is one of the great selling points of Joomla as far as I am concerned.
Anyway, on to your issue -- I took a look at it and found that the example code had a bug in it. It could never have worked, so don't feel bad about it!
I've reworked the example and tested it much more thoroughly, so you should feel confident to go back and grab it again.
http://www.metamodpro.com/support/recip … e-category
I also added the ability for the code to detect what section you are in when you are viewing a category (blog or list style). Every category is in one and only one section, so I think this makes sense.
By the way, the way that the table names are written (e.g. #__content) is a standard Joomla way of doing it, which uses the correct table prefix from your installation. You don't need to change this to "jos_content", as Joomla will look after this for you.
Again, thanks for reporting the bug, and I'm sorry it was wrong to start with :-(
Best regards,
Stephen
Re: Modules by sectionid not working as expected
Argh very cool. I didn't realise joomla could just #__ take that and change it as needed.
And yes, I've been watching the 1.6 progress, i've got to be honest im not very impressed. Looks like they are making a hash of the ACL, yay SECTIONS are gone but nay nested CATEGORIES or Multiple Categories has not surfaced. Those were the two big things for me ontop of your module control.
Plugin control would be good too, although I can't see an immeadiate reason for it.
Thank you very much for your swift response too, I'm eager to test this out. Thank you for your help.
Re: Modules by sectionid not working as expected
O dear,
Im getting errors now
normally:
Code:
Parse error: parse error in C:\xampp\htdocs\bloodsweatandcheers\modules\mod_metamod\helper.php(381) : eval()'d code on line 48
but the following if I pass an arrary:
Code:
Parse error: parse error in C:\xampp\htdocs\bloodsweatandcheers\modules\mod_metamod\helper.php(381) : eval()'d code on line 45
And here is my new receipe:
Code:
if ( $option == 'com_content' && $view != 'frontpage' ) {
$section_id = null;
if ( $view == 'section' ) {
/* section list pages (blog or list style) */
$section_id = (int)$id;
} else if (array_key_exists('sectionid',$_REQUEST)) {
/* if the section id is in the URL */
$section_id = (int)JRequest::getInt('sectionid',0);
}
if ( $view == 'category' ) {
/* if it's a category list or blog page, get the section that the
* category is in
*/
$my_id = $db->Quote( $db->getEscaped( (int)$id ) );
$query = "SELECT section from #__categories where id = $my_id";
$db->setQuery( $query, 0, 1 );
$row = $db->loadObject();
$section_id = (int)( $row->section );
}
if ( $section_id === null && $view == 'article' ) {
/* if it's an article page without the sectionid mentioned in the
* url, look up the section id for that article
*/
$nullDate = $db->Quote($db->getNullDate());
$my_id = $db->Quote( $db->getEscaped( (int)$id ) );
$jnow =& JFactory::getDate();
$now = $db->Quote( $db->getEscaped( $jnow->toMySQL() ) );
$query = "SELECT title, id, sectionid "
. " FROM #__content WHERE id = $my_id AND state = 1"
. " AND ( publish_up = $nullDate "
. " OR publish_up <= $now )"
. " AND ( publish_down = $nullDate "
. " OR publish_down >= $now )";
$db->setQuery( $query, 0, 1 );
$row = $db->loadObject();
$section_id = $row->sectionid;
}
if ($section_id == 1) return array (44,21,20,22,23,24);
if ($section_id == 2) return array (43,24,20,21,22,23);
if ($section_id == 3) return array (42,20,21,22,23,24);
if ($section_id == 4) return array (46,23,20,21,22,24);
if ($section_id == 5) return array (45,22,20,21,23,24);
return 31;
without arrary:
Code:
if ( $option == 'com_content' && $view != 'frontpage' ) {
$section_id = null;
if ( $view == 'section' ) {
/* section list pages (blog or list style) */
$section_id = (int)$id;
} else if (array_key_exists('sectionid',$_REQUEST)) {
/* if the section id is in the URL */
$section_id = (int)JRequest::getInt('sectionid',0);
}
if ( $view == 'category' ) {
/* if it's a category list or blog page, get the section that the
* category is in
*/
$my_id = $db->Quote( $db->getEscaped( (int)$id ) );
$query = "SELECT section from #__categories where id = $my_id";
$db->setQuery( $query, 0, 1 );
$row = $db->loadObject();
$section_id = (int)( $row->section );
}
if ( $section_id === null && $view == 'article' ) {
/* if it's an article page without the sectionid mentioned in the
* url, look up the section id for that article
*/
$nullDate = $db->Quote($db->getNullDate());
$my_id = $db->Quote( $db->getEscaped( (int)$id ) );
$jnow =& JFactory::getDate();
$now = $db->Quote( $db->getEscaped( $jnow->toMySQL() ) );
$query = "SELECT title, id, sectionid "
. " FROM #__content WHERE id = $my_id AND state = 1"
. " AND ( publish_up = $nullDate "
. " OR publish_up <= $now )"
. " AND ( publish_down = $nullDate "
. " OR publish_down >= $now )";
$db->setQuery( $query, 0, 1 );
$row = $db->loadObject();
$section_id = $row->sectionid;
}
/* Now customise any of the following rules for your use.
* $section_id will correspond to the section id of the
* article being displayed (if one is being displayed!)
*/
if ($section_id == 1) return 38;
if ($section_id == 2) return 37;
if ($section_id == 3) return 35;
if ($section_id == 4) return 39;
if ($section_id == 5) return 40;
The error always reports back on which ever is the last line number. and referrs back to the line in the helper file that calls the php block. So i doubt theres a problem there.
Can you rescue me again.
Cheers,
Re: Modules by sectionid not working as expected
You just need a final } after the last line. I changed the way that it works in the example code (previously you didn't need it, now you do).
So your final lines would be:
Code:
if ($section_id == 5) return 40;
}
The reason I did this was because of adding support for "uncategorised" articles that have a section id of 0. It's a bit complicated and wouldn't have affected things in your case. But just add the '}' and you'll be fine.
Re: Modules by sectionid not working as expected
Hi,
This sounds like I'm trying to do the exact same thing. I want to display a vertical menu of our categories for each section when someone is looking at an article from that section or its category.
Do I have to have the specific menu module published?
I'm not sure what settings to have turned on, etc.. MetaMod is so powerful and appears that it would solve my dilemma!
And, I used the "Section Detection:" code, put it in the "PHP" area of the MetaMod area, tried changing and tried "if ($section_id == 3) return 30;" where it says to customize it.
...but something is not right as it's not showing up when viewing an article in a category under the section.
Re: Modules by sectionid not working as expected
Well the section detection code from the recipe page should work (it's been tested), so it's probably something simple that you've missed:
1 - check that the MetaMod is turned on and set to the correct module position. Also check that it's set to the correct Menu Assignment (i.e. that it would show up on the page that you are looking at). For debugging, try setting it to "all" pages just to be sure.
2 - does module 30 exist and is it enabled/published?
3 - turn on debug mode in the MetaMod. Does it give you any messages about what's going on? At the end of the debug output it should say "including modules: 30". If the "30" is not there then there's something wrong with the rule, but check what else is written there.
Hope that helps,
write back if you still can't find what's wrong,
Stephen
- Index
- » MetaMod
- » MetaMod General Support
- » Modules by sectionid not working as...
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5944
- Posts this week:
- 2
- User Info:
- Total Users:
- 7655
- Newest User:
- martha48
- Members Online:
- 0
- Guests Online:
- 160
- 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