PDA

View Full Version : Automatically change certain words (text) into links?


nikki712
08-01-2009, 03:58 PM
Is there a way to automatically change certain words in posts into links? For example, if someone types the word California on my forum, is there a way to make that word turn into a link to my California page on my site? I looked for a hack for this, but couldn't find one. Maybe I'm overlooking it. Any help would be appreciated. Thanks!

Lynne
08-01-2009, 04:17 PM
There are Replacement Variables, but those are site wide, not just for posts. You can write a simple plugin to do a search/replace for words in posts:
location: postbit_display_complete
$word = array(
'word1',
'word2'
);

$link = array(
'<a href="/forums/link1.php">Word1</a>',
'<a href="/forums/link2.php">Word2</a>'
);

$this->post['message'] = str_ireplace($word, $link, $this->post['message']);

nikki712
08-01-2009, 04:30 PM
What do I put in the place of "message" in that plugin? Thanks!

Lynne
08-01-2009, 04:49 PM
The only things you would change are the $word and $link arrays. Leave the last line alone.

That plugin changes the words when the message is parsed. If you need to change it when the message is created, you'd have to use a different hook location and the code would change. I haven't done that before, so I don't have a quick plugin to post for that.

nikki712
08-01-2009, 04:56 PM
Got it! Thanks so much!

matthewhotdude
08-04-2009, 05:05 PM
Where am I looking for this postbit_display_complete Because I can't find it

Lynne
08-04-2009, 05:28 PM
Where am I looking for this postbit_display_complete Because I can't find it
It's a hook_location. You find it when you create a plugin.

Chainspell
03-14-2010, 03:23 AM
not working for me :( im on vb4.0

--------------- Added 1268554434 at 1268554434 ---------------

it works wonderfully on the forums. any reason why it doesnt work in the blogs section?

Naama
08-05-2010, 04:09 PM
Hi and thank you for this code, it works great!

But there is any chance that I can make it convert ONLY one word (in case that the word repeat herself) in the text to link?

Thanks :)

simoneaton
08-21-2010, 05:41 PM
Tried this and it is now working for me as I get this error message;

Parse error: syntax error, unexpected '=' in /home/sportsbo/public_html/includes/class_postbit.php(314) : eval()'d code on line 36

Parse error: syntax error, unexpected '=' in /home/sportsbo/public_html/includes/class_postbit.php(314) : eval()'d code on line 36

Parse error: syntax error, unexpected '=' in /home/sportsbo/public_html/includes/class_postbit.php(314) : eval()'d code on line 36

Parse error: syntax error, unexpected '=' in /home/sportsbo/public_html/includes/class_postbit.php(314) : eval()'d code on line 36

Parse error: syntax error, unexpected '=' in /home/sportsbo/public_html/includes/class_postbit.php(314) : eval()'d code on line 36

Parse error: syntax error, unexpected '=' in /home/sportsbo/public_html/includes/class_postbit.php(314) : eval()'d code on line 36

BirdOPrey5
08-21-2010, 07:18 PM
There's probably a typo in your code...