Skip to:
Content
Pages
Categories
Search
Top
Bottom

Codex linking?

  • @ipstenu

    Moderator

    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!

Viewing 4 replies - 1 through 4 (of 4 total)
  • @_ck_

    Participant

    It’s probably a 5 line plugin to do that.

    Give me an example of what the destination URL looks like.

    @_ck_

    Participant

    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$2'>$2</a>",$text);
    return $text;
    }
    ?>

    the above is missing two $2, should look like

    <a class='wiki_link' href='$url$2'>$2</a>

    @ipstenu

    Moderator

    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…

    @_ck_

    Participant

    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)

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar