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
- » Control modules based on page...
Control modules based on page content/keywords/description for J.2.5
Control modules based on page content/keywords/description for J.2.5
Hello,
Ive used to use the "Control modules based on page content/keywords/description" in a Joomla 1.5 website, i am in progress to upgrade my website in Joomla 2.5, but the recipe would not work with Joomla 2.5.
I need your help to make recipe work in Joomla 2.5
Thank you for your support!
Re: Control modules based on page content/keywords/description for J.2.5
Re: Control modules based on page content/keywords/description for J.2.5
Re: Control modules based on page content/keywords/description for J.2.5
Hi gdi,
I've just done some double-checking for that recipe and have made a few minor changes on page http://www.metamodpro.com/metamod/recip … escription
Can you please try the recipe again and see how it works for you?
Best regards,
Stephen
Re: Control modules based on page content/keywords/description for J.2.5
Hello Stephen,
I tried the above recipe, but can't make it work. I use the metamod to appear some modules based on different content words from Joomla search. When i enable the dubeg i can see the metamod there, but it not delivery the module.
Thank you
Re: Control modules based on page content/keywords/description for J.2.5
hmmm, I wonder what's going on there.
Ok, let's test that the 1st part works, that it can retrieve the actual data from your document:
$document = JFactory::getDocument();
$kw = $document->getMetaData('keywords');
$desc = $document->getMetaData('description');
$buffer = $document->getBuffer();
$content = $buffer['component'][''];
echo "Keywords: $kw <br />";
echo "Description: $desc <br />";
echo "Content starts with: " . substr(htmlentities($content), 0, 50) . "<br /">
Does that give you the right information?
If that works ok, can you please paste into this forum the exact PHP you are using? Then I can test that directly.
Thanks,
Stephen
Re: Control modules based on page content/keywords/description for J.2.5
Hello Stephen,
Can you please specify me where to put the code that you have give to me, i tried to replace it below with the $document = JFactory::getDocument(); but it doesnt work.
The code that I use is from the URL posted by you above.
Thank you again for your help.
My current metamod code:
<code>
// To set it up, just edit the "$source", "$case_sensitive",
// "$allow_as_substrings", "$names" and "$max_num_modules"
// variables below. The "$names" array contains the
// words/phrases that you want to search for, and the module
// ID or module position to use when any one of them is found.
$source = "content"; /* either "keywords", "description" or "content" */
$case_sensitive = false; /* set to true or false */
/* if you set $allow_as_substrings to true, then the search
* will pick up "billybob thornton" even if you are trying
* to search for "bob thornton". Set it to false to make
* sure that there's an least 1 non-alphabet character on
* each end of the string you are searching for.
*/
$allow_as_substrings = false; /* set to true or false */
$max_num_modules = 3; /* it will just give you the first 3 it finds */
/* In this array, the first part is the text to search for, and
* the last part is the module id to include if that text is
* found. Add as many as you like.
* Remember every line has to end in a comma EXCEPT the last one!
*/
$names = array(
"Internet Links" => 322
);
/*****************************************/
/* you shouldn't need to edit below here */
/*****************************************/
$document = JFactory::getDocument();
switch ($source) {
case "keywords":
$content = $document->getMetaData('keywords');
break;
case "description":
$content = $document->getMetaData('description');
break;
default:
$buffer = $document->getBuffer();
$content = $buffer['component'][''];
}
$names_escaped = array();
$names_case = array();
foreach ($names as $key=>$module) {
if (!$case_sensitive) {
$key = strtolower($key);
}
$names_escaped[preg_quote($key)] = $module;
$names_case[$key] = $module;
}
$names = $names_escaped;
$names_only = str_replace('/','\/',implode("|", array_keys($names)));
$word_boundary = $allow_as_substrings ? '' : '\b';
$result = preg_match_all("/" . $word_boundary
. "(" . $names_only . ")"
. $word_boundary . "/"
. ($case_sensitive ? '' : 'i'), $content, $all);
if ($result > 0) {
$modules = array();
foreach ($all[0] as $matched_name) {
$module = $names_case[$case_sensitive ?
$matched_name : strtolower($matched_name)];
if ( !in_array( $module, $modules) ) {
$modules[] = $module;
}
}
if ( count($modules) > $max_num_modules ) {
return array_slice( $modules, 0, $max_num_modules );
}
return $modules;
}
</code>
Re: Control modules based on page content/keywords/description for J.2.5
Hi,
well, I copied and pasted the code directly from above except without the <code> markers, and it worked perfectly with no warnings.
Is this maybe a matter of module 322 (your target module) not being set up properly? What happens if you replace that with another module id for a different module?
See the Quick Start guide for more discussion on how to set it up properly.
Cheers,
Stephen
- Index
- » MetaMod Pro
- » MetaMod Pro General Support
- » Control modules based on page...
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5943
- Posts this week:
- 2
- User Info:
- Total Users:
- 7642
- Newest User:
- mary26
- Members Online:
- 0
- Guests Online:
- 162
- 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