Hello,
I’m looking to see if an extension like this already exists (I can’t find it) or has enough interest from other people that it should be made.
I’m assigning Pages module URLs to many of my posts, and then linking to these URLs in various places on my site. Every so often, I change the URL for the page and must go through my whole site to update the relevant links.
I’d like to have a feature where I can link using something like this (the actual syntax doesn’t matter):
<a href="http://{pages_url">Link to Entry 62</a>
And the URL it generates is the most recent Pages module URL to that entry.
Is this already possible somewhere? Can it be done?
Thanks, Matt
I made you this. Here’s how you use it:
{exp:pages:url entry_id="9"}
Put this function in the mod.pages.php file.
function url()
{
global $PREFS, $TMPL;
$pages = $PREFS->ini('site_pages');
if (
false !== $pages
&& isset($pages['uris'])
&& @array_key_exists("entry_id", $TMPL->tagparams)
&& isset($pages['uris'][intval($TMPL->tagparams['entry_id'])])
)
{
return $pages['uris'][intval($TMPL->tagparams['entry_id'])];
}
}
EllisLab, Inc: I, Robert Wallis, officially release all rights to the above code snippet on this Monday, January 14th 2008, you may use it in any commercial or non-commercial product.
You could add a “custom weblog field” and then pass that through the template using
{exp:pages:url entry_id={custom_field}}
But that won’t allow you to put links anywhere in an entry. The Pages module looks like a new hack for the purpose of SEO, because you can specify any url for an entry. (But really, aren’t most SEOs just snake oil anyway, Google has armies of CS Doctors that are much smarter than some random marketing guy that says “.html extensions give you better page rank”.) So it comes down to just site organization. Often happens to me too, I want template access in my entries. The reason you can’t do it probably has to do with speed, security, and other things.
I think what you really want, is a find and replace feature for entries.
Or modify the Pages module to automatically update entries with some preg_replace() goodness when you change the url.
Hey guys -
Robert, thank you for offering a solution for this!
For others, please note that hacks are not supported - and in almost all cases, there are appropriate ways to add a feature without using a hack.
For instance, in this case -you could easily add this feature via a custom plugin. This would allow you to have the features, without an unsupported hack that needs to be tracked for updates, and in a format which can be easily re-distributed.
If you’d like to go with a plugin, I’d recommend reviewing our development documentation.
Thank you again!
Sorry, I should have made this a plugin in the first place but I just made my first plugin this morning: http://ellislab.com/forums/viewthread/68937/
So I converted this hack into a plugin and attached it below. Now you can use syntax more like the original comment:
{exp:pages_url entry_id="9"}
To use it within entries you can use the Allow EE Code plugin 😊
Hmm, I couldn’t get this to work. I wrapped the allow ee code tags around my custom field, and put the pages_url tag in it, but nothing came out.
Any idea why?
In the template code you use the {exp:allow_eecode} tag surrounding a weblog output field. Then in the actual blog post you use {exp:pages_url entry_id="9"}.
However, as it is documented, if you use allow_eecode, then anyone that has access to post a blog will have access to anything else in the site that ee tags can access. So you would never want to put it around comments or another field that a random internet user could change.
Yep, I was using it exactly like they have it on the docs (even with the same field, {body}):
{exp:allow_eecode}
{body}
{/exp:allow_eecode}
And in the body, I have your {exp:pages_url entry_id="9"} code, but it just comes out blank.
I’ll keep investigating, maybe turn on the debugging options.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.