(EVO) You could write a plugin "OnParseDocument"
Example
$output = &$modx->documentOutput;
$output = str_replace("maddona", '<a href="maddona.html">maddona</a>', $output);
return $output;
Thanks but I am an utter novice! Are you saying create a plugin called ’OnParseDocument’ In the plugins section, then copy that code into it, when I chaged the madonna keyword of course? I am assuming that the parsing bit means it will add the link as the document is served? Also what would I put in the configuration box on this plugin? I fully understand if you don’t have the time to answer these, I am ok with kid’s bullet points though!
WOW! I’ve done it! I know what you mean now, by the parse thing, Hey thanks a lot, really appreciate that.
What about if I only want it to link the 1st instance of a particular keyword on any particular page? I also need it to limit the amount of single keywords to link. I.e., I want it to link a maximum of 3 keywords per page, and only 1 instance of each keyword, so if there’s 2 ’Madonna’ keywords, only do the first one.
Another problem I just came across is, when the href link is the same name as the keyword (very likely indeed!) then the plugin sees this word as well and tries to put a link on the link! So need it to ignore the href as well. Any helpful php wizards out there?
I tried it, but when testing in my browser (separate PC) the page hangs at a blank white display. I assume the plugin is triggered through the "OnParseDocument" event?
It works fine for me, BUT if you use the same keyword in the href text it also becomes linked which messes the whole web page up of course! I don’t have enough php knowledge to edit the kind gentleman’s code. Need to add the following:
1) A condition that stops the plugin seeing the href as the text specified to link to
2) A condition that tells the plugin to only hyperlinke the first example of the text it sees per page
3) A condition that allows the creation of more than one keyword to link, although this one’s likely to be simple
4) A condition that tells the plug in to stop at 3 links per page (3 different keywords that is)
No idea how to do it. >:(
Quote from: benchesters at Aug 31, 2010, 11:35 AM
1) A condition that stops the plugin seeing the href as the text specified to link to
Add some space to the word we search.
$output = str_replace(" maddona ", ' <a href="maddona.html">maddona</a> ', $output);
Quote from: benchesters at Aug 31, 2010, 11:35 AM
2) A condition that tells the plugin to only hyperlinke the first example of the text it sees per page
Use this php function
http://www.webmaster-talk.com/php-forum/21334-str_replace-only-once-occurence-only.html
Quote from: benchesters at Aug 31, 2010, 11:35 AM
3) A condition that allows the creation of more than one keyword to link, although this one’s likely to be simple
Just add another line:
$output = str_replace(" maddona ", ' <a href="maddona.html">maddona</a> ', $output);
$output = str_replace(" mrhaw ", ' <a href="mrhaw.html">mrhaw</a> ', $output);
Quote from: benchesters at Aug 31, 2010, 11:35 AM
4) A condition that tells the plug in to stop at 3 links per page (3 different keywords that is)
Need to google that to...
I changed keyword but still get blank page. I’m using Revo. I trigger the plugin "OnParseDocument"