Relative permalinks from the root directory.
If your post’s permalink looks like this:
http:/example.com/blog/some/stuff/here/storyname
then you link to this href:
/blog/some/stuff/here/storyname
This won’t help if you switch directories around, or switch your permalinks around, but there’s no way to help that anyway. This is the best compromise, since it will be fine if you switch domain names, but will actually work from all points on your site.
I see. Thanks. Wouldn’t it be grand if I can just code say (a href=”ZZZ”)text(/a) in the post editor, where ZZZ is the post-slug or the post-ID, and WordPress will automatically convert it to a blog-independent, host-independent URL? This means I don’t embed my blog’s file structures in my content, which I thought was important.
Wasn’t this requested before? As a plugin, perhaps?
eHarmony Blog
If you have any kind of Exec PHP plugin, that lets you put PHP in your posts, then you could use the get_permalink($id) function to get the link to any given post by ID.
It would be possible to create a quicktag for this sort of thing using a plugin. Hmm… Gimme a while to think about it.
Edit: Okay, that was a while. Here you go:
http://ottodestruct.com/wpstuff/postlink.zip
It’s a plugin. Install it, activate it. You can then use tags of the form:
[ID=###]Link to my post[/ID]
In your posts. The ### should be the number of the post ID you want to link to. This will be replaced by an a href permalink. If your permalinks change or your blog moves or whatever, these will change too, as long as you have the plugin working.
Downside: If you disable the plugin, they all change back to the [ID=] stuff. The replacement happens at display time, not at post time.
Otto, the file activated successfully, but apparently doesn’t do anything. [ID=1]Link to my post[/ID]
stays that way.
Doh. I had it one way, then changed it, and forgot to test that change.
Change the two lines inside the foreach() block to these:
$text = str_replace("[ID=".$val[0]."]","<a href=\"".get_permalink($val[0])."\">",$text);
$text = str_replace("[/ID]","</a>",$text);
That will fix it.
Finally! — blog-independent, platform-independent, webhost-independent hyperlinking between posts of one blog. It worked in excerpts, posts, RSS feeds and even “email this post”‘s. THANK YOU!
I think this needs to be put in WordPress’s plugin repository or whatever-it’s-called. Or, at the least, this feature be added to WordPress.
eHarmony Blog
Oh Otto I’m sorry, but, apparently, only the first [ID] pair is converted. May I trouble you and ask your php wizardry again?
Whoops. preg_match_all doesn’t work with foreach() in quite the way I thought it did.
Anyway, problem fixed. Download it again, same link as before. Just overwrite the old version with the new one.