• I am using the Wiki Page Links plugin and want to change it so that it works with WP Wiki. I want to append a hardcoded path to my directory in the URL to the page name so that all Wiki Links go to my Wiki.

    Right now:
    [mypage]

    Links to:
    example.com/mypage

    I need to point to a Wiki page like this one:
    example.com/wiki/mycategory/mypage

    So I need to add /wiki/mycategory/ to the URL constructor, but I don’t know the syntax.

    Here is the code I think that needs to change:

    list($link, $page_title) = $this->wiki_get_piped_title($full_link);
    
    //We have a page link.
    //TODO: cut down on db hits and get the list of pages instead.
    if ( $page = get_page_by_title(html_entity_decode($link, ENT_QUOTES)) ) {
    
    //I THINK THIS HREF NEEDS CHANGED TO INCLUDE PATH TO /wiki/mycategory
    $content = str_replace($match,
    "<a href='". get_permalink($page->ID) ."'>$page_title</a>",
    $content);
    }

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi jmobi,

    I made this plugin because I found myself linking to (a few) pages a lot and wanted an easier way to do that. WP Wiki looks pretty cool, but it’s not something I’m going to use on my sites.

    However! This plugin is all free software. You’re very welcome to take the code and create a new plugin based on it to do whatever you want. If make non-WP Wiki-specific changes you think would be useful for the original plugin, I’d love for you to let me know, but really, you’re free to do what you like with it.

    I’m glad you’re finding it useful. ??

    Thread Starter jmobi

    (@jmobi)

    Thanks so much for the reply. It really is a great plugin.

    My problem is I don’t program PHP too much anymore and I cannot figure out how to append my path to the URL.

    Specifically, I do not know what this is doing:
    "<a href='". get_permalink($page->ID) ."'>$page_title</a>",

    I want to construct the href so that I can hardcode in something like this:
    "<a href='". get_permalink(/wiki/mycategory/$page->ID) ."'>$page_title</a>",

    That doesn’t work obviously, but that is what I am hoping you can help me with. I just want to add to the URL constructor.

    Can you tell how to change the code to alter the path?

    Okay, well, like you guessed, this is what’s generating the link:

    "<a href='". get_permalink($page->ID) ."'>$page_title</a>"

    In php, strings are joined together with the . operator. get_permalink() is a WP API function that retrieves the URL for a post or page.

    You need to replace that function with a function either from the WP Wiki API (if they have one) or one you make yourself. It could be as simple as something like this:

    function get_wiki_link($page_title)
        return "https://example.com/wiki/mycategory/" . $page_title
    end

    Although that’s only going to work for your website and only so long as your URLs don’t change. There may be better ways to do it, particularly, as I said, if WP Wiki gives you a way to look up their pages.

    Good luck!

    Thread Starter jmobi

    (@jmobi)

    OK, thanks, I did get it working.

    I took that idea of creating a function which returns a var and replaced the content with this:

    "<a href='$myWikiLink'>$page_title</a>",

    If you ever get that Admin Console you mentioned in the *TO-DO*, it might be nice to make the path a variable. Not sure if other people have this need.

    The benefit is that I can link directly to my Wiki without having to go through the trouble of searching in the link interface.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Changing Path to Wiki Page Links to Point to Wiki Directory’ is closed to new replies.