WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Soft and robust vs. brittle links between posts (10 posts)

  1. Anonymous
    Unregistered
    Posted 9 years ago #

    Hi folks,
    I've searched through the Wiki and through the support forum on phrases like "link between posts", "link another post", "link to post", etc., and I've tried using the_permalink(ID) within an actual WordPress posting, but still I can't figure out something...
    Specifically, I would like to link from one WordPress posting (call it 'Linker') to another WordPress posting (call it 'Linkee'), and I want that link to be 'robust' -- meaning that it doesn't break if, for example, I change the name of the category containing Linkee, or I change my permalink structure. This seems like a really basic feature of any system for managing content, but I'm afraid I'm stumped on the question of how to actually do it!
    Obviously, just linking to an ordinary URL like http://mydomain.com/archives/examples/linkee-story/ won't work at all, because if I change the permalink structure so that Linkee sits at mydomain.com/archives/examples/2004/linkee-story, then the link will break. Or if I change 'examples' into 'spiffy-examples', it will also break.
    Also, including the_permalink(ID) within a posting, hoping to get WordPress just to generate an appropriate 'soft' URL on-the-fly for a given article ID, unfortunately leads only to confusion and disorientation on the part of WP, which does un-pretty things with the rest of the post.
    Could anyone point me in the right direction for creating robust links between postings, that won't just break the moment I change a category name or otherwise fiddle with my permalink structure?
    Thanks!
    Greg

  2. GregM
    Member
    Posted 9 years ago #

    Sorry I wasn't logged in -- that was me, rather than 'Anonymous'!
    Greg

  3. jabecker
    Member
    Posted 9 years ago #

    Oops. I really meant for those not to be links. Sorry about that.

  4. GregM
    Member
    Posted 9 years ago #

    Yes, including the database query explicitly will definitely do it -- thank you for pointing out at least one way of achieving a link between posts which doesn't break the second a change is made in how the posts are served up!
    Unfortunately, though, it gives up on the elegance of permalinks and the goal of providing the user with cleanly formatted links across the whole blog.
    A large part of the benefit of using permalinks is that links within your own site are formatted cleanly, so the visitor never needs to see the database query string. This is how all the other links work, which WP generates itself -- e.g., links to categories, links to posts within categories, etc.
    So, it sounds like there's a trade-off: either use permalinks throughout, even in your own posts, and it will all be clean...but brittle...or give up on them altogether for links within your own posts, in which case they are robust...but ugly.
    You've helped me to clarify my own thinking about the question and make it more explicit... Now I realize that what I'm really after is this: is it possible to use permalink-style links *consistently*, all throughout a blog, without having them break due to structural changes in the way the database entries are presented (e.g., changing a category name, changing an article title, etc.)? Or does robustness to changes in presentation require mixing in some non-permalinks?
    Thanks in advance for any more suggestions!
    Greg

  5. DianeV
    Member
    Posted 9 years ago #

    Interesting question. I think what you're calling "permalink-style links" are really database links that have been (as I've seen it called here) "prettified".
    So what you're asking for is to be able to use prettified URLs for the blog but to reference them on occasion as database-style links (by post number), then have WP check the DB post-number links against prettified URLs used for that post. That would be "any and all prettified URLs currently used for that post".
    In case you're wondering, no, my PHP skills are not up to this type of task.

  6. Beel
    Member
    Posted 9 years ago #

    If you change the lock the old combination ain't gonna work. You can't make a permalink using variables you might change - it ain't permanent. Even if you used, as mentioned, "index.php?p=X" that is impermanent if you change the post id at some time in the future. The best you can do if a change is made is a redirect.

  7. GregM
    Member
    Posted 9 years ago #

    Hmmm, yes, as you say -- if you change the lock, the old combination ain't gonna work...
    That's a large part of the reason why content management systems were invented in the first place -- so that publishers don't have to go manually running through their pages and changing combinations whenever they decide to change the lock. CMSs do that for them. That's also why WP *already* achieves this feat perfectly well for thousands upon thousands of links across hundreds of different blog installations, for every single link on the blog which it generates itself.
    The question is: is there a way to utilize that exact same functionality in material which *I* generate, so that I don't need to make manual changes in links whenever something gets moved or renamed?
    Maybe I'm making this sound difficult somehow, but it's a built-in capability of every main CMS out there, it's a built-in capability of every HTML editor that does site management, etc., etc. Nobobdy but nobody goes around manually changing all their links when they want to change a file name, etc.
    Thanks again for any more insights,
    Greg

  8. GregM
    Member
    Posted 9 years ago #

    Kafkaesqui, that's an *extremely* clever solution to the problem -- your extra mod_rewrite rule lets you translate clean links which don't use any category names, dates, etc.. I guess this same rule would pop out if I just defined my permalink style to use *only* the post name, without including any of the other %variables%? So one possible solution, as you say, is to use a mod_rewrite rule like this one (or maybe whatever WP might spit out with a plain-Jane permalink structure) *at the same time as* the rules for your chosen permalink structure. Then, the only way of breaking the link would be to change the file name, but changes to permalink structure or category names would be perfectly safe.
    From the feedback so far, I'm going to guess that WP lacks any built-in way of achieving the feat I was originally hoping to achieve. If this really is the case (which would be quite a glaring hole in an otherwise exceptionally well thought-out approach to permalinks, IMHO), then your solution sounds like an excellent work-around.
    Thanks a bunch!
    Greg

  9. Michael Adams (mdawaffe)
    Member
    Posted 9 years ago #

    Just today I decided I needed to look into this as well. You're initial post about using the_permalink() got me thinking.
    Normally you can't use php inside posts, but with the thanks of James Van Lommel's RunPHP plugin, you can. I think there are a couple plugins out there that offer similar functionality; I have no idea if any are better or worse. This is the one I first hit upon, and it works for me. It seems nice since it only evaluates PHP code for those posts you specify.
    After installing RunPHP, I was able to insert the following code in my post:
    ">Post 24
    and it worked like a charm. I used get_permalink(ID) because the_permalink() only returns the permalink for the current post (I think?). Also, it needs to be echoed since the funtion does not display the permalink, it only figures out what it is.

  10. GregM
    Member
    Posted 9 years ago #

    Folks, this just keeps getting better! I'll scope out the RunPHP plugin, because as you describe it, it sounds like it could provide *exactly* the capability I was after originally!
    Many thanks,
    Greg

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.