Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
Need help getting started!
Need help getting started!
Hi,
I am a musician, not a programmer. I really need this module, but can't understand how to get the php code to display a particular module for a category.
Could you please give me an example of the code that would make moudule #138 appear on all pages in category #41.
That could get me started. I am not completely ignorant of php, but I am confused by the recipe. When it says "now customize" I am not sure if I am supposed to be placing that code somewhere else in the script to get it to work, or what. So, if you could give me this specific example I might get it from there.
Thanks very much!
Re: Need help getting started!
Hi jamieandreas,
sorry that the "categories" recipe is one of the longest and most complicated ones on the site. That's going to change in the next few weeks with a new version of MetaMod... but until then we're stuck with it.
The "now customise" bit is actually simpler than you thought. You see the 3 lines below that comment:
if ($category_id == 1) return 55;/* on category 1, return module 55 */
if ($category_id == 2) return 56;/* on category 2, return module 56 */
if ($category_id == 3) return 57;/* on category 3, return module 57 */
Well instead of those 3 lines, just use one of these as a template to do what you need it to do.
e.g.
if ($category_id == 1) return 55;
That means, for category 1, use module 55.
If there are different modules that you want to use for different categories, then just add additional lines just like that one, immediately following that line, just like in the example on the web page.
Obviously, you will need to change the "1" and the "55" to suit your particular site.
Lastly, if you want to return more than 1 module for a particular category, then you need to put the module ids in double quotes like this:
if ($category_id == 1) return "55,56";
Hope that helps - please write back if you need more help with it.
Cheers,
Stephen
Re: Need help getting started!
Oh, by the way here's the complete recipe, including the ID numbers you supplied:
Code:
$category_id = null;
if ( $option == "com_content" ) {
if ( $view == "category" ) {
/* category list pages (blog or list style) */
$category_id = (int)$id;
} else if (array_key_exists("catid",$_REQUEST)) {
/* if the category id is in the URL */
$category_id = (int)JRequest::getInt("catid",0);
}
if ( $category_id === null && $view == "article" ) {
/* if it's an article page without the catid mentioned in the url */
$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, catid "
. " 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();
$category_id = $row->catid;
}
}
/* Now customise any of the following rules for your use.
* $category_id will correspond to the category id of the
* article being displayed (if one is being displayed!)
*/
if ($category_id == 41) return 138;/* on category 41, return module 138 */
Note: this will display the module on articles that are in category 41 as well as any pages that display category 41 in list or blog view.
Re: Need help getting started!
Thanks Steve, that makes it clear.
It also makes it clear that something must be wrong because I still can't get it to work. The thing is, I think I had it working, and modules were showing like their supposed to, and now they don't.
I am trying to think of what other reasons might be the cause of metamod not working for me, now that I know the actual code is correct.
Any ideas?
Jamie
Re: Need help getting started!
Hi Jamie,
a couple of ideas:
1 - the recipe I pasted above assumes that your database prefix is "jos_". Ideally you should change the line above that says "... FROM jos_content " to "... FROM #__content". (that's a # followed by two underscores)
2 - have you read the Quick Start page? http://www.metamodpro.com/metamod/quick-start
3 - make sure you don't have anything in the datetime boxes, or the "Quick module id include" box in MetaMod. Basically just use a new blank metamod with only the PHP code from above, plus a title, plus any Menu Items selected for the module to appear on.
Hope that helps,
Stephen
Re: Need help getting started!
By the way, if you install the newest version of MetaMod (2.4c) then you can replace the ENTIRE rule above with this simple line:
if ($content_genius->check("category_id = 41" ) ) return 138;
Cheers,
Stephen
Re: Need help getting started!
Hi Steve,
No matter what I do, I can't get it to work. How about this, how about I give you my login info and you take a look and see if you can get it to work?
If you want to do that, just give me your email and I'll send you the info.
Jamie
Re: Need help getting started!
Hi Jamie,
it's all working now. I just used the recipe:
if ( $content_genius->check("category_id = 41" ) ) return 138;
The only real problem was that you had set the MetaMod to display on "none" pages. You did need to do that for the target module, but not for the MetaMod. The MetaMod has to be set to appear on some pages, otherwise, well, it just wouldn't display.
All done,
Best regards,
Stephen
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5942
- Posts this week:
- 2
- User Info:
- Total Users:
- 7627
- Newest User:
- rudys68879
- Members Online:
- 1
- Guests Online:
- 152
- Online:
- rudys68879
Forum Legend:
Topic
New
Locked
Sticky
Active
New/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky/Active/Locked