Info
- 5 posts
- 2 voices
- Started 3 years ago by Ipstenu
- Latest reply from _ck_
- This topic is not a support question
Codex linking?
-
- Posted 3 years ago #
So I'm reading this blog post, all about bbPress and WordPress and I realize something. You can link on the WP forums to their wiki.
3. Link to Codex article by using the wiki code of two beginning and ending brackets. [[Template Hierarchy]] will create a link to that article in Codex.
I have bbPress. I have a MediaWiki. How did they do that!? I'd like to implement that!
-
- Posted 3 years ago #
It's probably a 5 line plugin to do that.
Give me an example of what the destination URL looks like. -
- Posted 3 years ago #
Untested. Actually the forum is deleting some of the code so use it from here:
http://pastebin.com/f54a958de<?php /* Plugin Name: Wiki Link */ add_action('post_text','wiki_link',200); function wiki_link($text) { $url="http://example.com/path_to_wiki?terms="; $text=preg_replace("/(\[\[(.+?)\]\])/si","<a class='wiki_link' href='$url'></a>",$text); return $text; } ?>the above is missing two $2, should look like
<a class='wiki_link' href='$url$2'>$2</a> -
- Posted 3 years ago #
The destination URL would be http://wiki.mydomain.com/wiki/PAGE And it cleverly sees the spaces (like 'Main Page') and turns that into underscores (Main_Page).
<?php /* Plugin Name: Wiki Link */ add_action('post_text','wiki_link',200); function wiki_link($text) { $url="http://example.com/path_to_wiki/"; $wiki= str_replace(" ", "_", "$ 2"); $text=preg_replace("/(\[\[(.+?)\]\])/si","<a class='wiki_link' href='$url$wiki'>$ 2</a>",$text); return $text; } ?>It does eat that $2 doesn't it...
-
- Posted 3 years ago #
There's no way your version works because the str_replace is executed immediately and the $2 isn't available at that time. The regex would either have to use a callback or be expanded to catch words (or look on php.net for the /e modifer)
-
You must log in to post.