Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Custom Error Page
Hi, I have a quick question that’s probably quite simple for the seasoned Textpattern user.
I recently converted to Textpattern from Wordpress. I managed to retain the permalink structure (/url/archives/post-title) to avoid old permalinks becoming defunct, but I’ve also deleted some posts, some of which still get a lot of requests.
Is there any way to generate a custom error page depending on the URL of the originating request. Say, if someone tried /url/archives/post-that-no-longer-exists, I’d like to be able to generate an error page that said something along the lines of, “The article Post That No Longer Exists no longer exists here, sorry.”
My very basic knowledge of PHP tells me there’s an environment variable that stores the URL they accessed, so it would just be a matter of taking that, and automatically transforming it into a readable format, right?
Offline
Re: Custom Error Page
Hi nostrich
and welcome to txp.
Error pages are handled by txp in presentation>error_default
you might be able to do what you are looking for by somehow echoing the last part of the url and I’m sure someone with php knowledge will provide you with the code here.
Last edited by colak (2008-04-15 15:41:14)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#3 2008-04-15 18:20:34
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Custom Error Page
I’m doing it like this:
The page you were looking for, http://site.com<txp:page_url />, does not exist.
Offline
Re: Custom Error Page
Now I’m confused, Els – if indeed the page does not exist, what can <txp:page_url />
return?
Honest question…
Keith
Blyth, Northumberland, England
Capture The Moment
Offline
#5 2008-04-15 18:45:12
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Custom Error Page
It’s just returning the requested URL. Try this (my site): http://kynoblog.com/non-existing-url :)
Offline
Re: Custom Error Page
Doh!
I realised after I typed what it would probably do, and have just put it into my own 404 page.
It is indeed rather cool!
Keith
Blyth, Northumberland, England
Capture The Moment
Offline
Re: Custom Error Page
That’s very neat Els. I didn’t realise you could do that. :)
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
Re: Custom Error Page
Hey, thanks for the replies. I know how the errors are handled, but I didn’t know about <txp:page_url />
. However, I was hoping I’d be able to make it a little prettier, if possible. Taking for example myblog.com/dead-post, and make it turn that into “The post titled Dead Post … etc.”
I realise that’s probably not a Textpattern question, rather a PHP one, but it’s worth a shot.
Regardless, thanks for the txp tag suggestion!
Offline
Re: Custom Error Page
I didn’t know it worked on 404 pages either. Neat, thanks Els!
But a quick question on this topic: why is <txp:page_url type="t" />
not available? According to Textbook, we can grab section, category, id, but not title. Is there some technical reason why the title’s not included in the tag options?
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Custom Error Page
All <txp:page_url />
does is return htmlspecialchars($pretext[$type]);
, so if ‘title’ is available in the $pretext array, you could use it. On error pages, I don’t think that’s possible, because if the article can’t be found, the title can’t be found either. And in cases where you can find the article, you can use <txp:title />
.
The topic starter could try this to display only the title with uppercased words (not tested):
<txp:php>
$parts = explode(rtrim(page_url(array()), '/'));
echo ucwords(str_replace('-', ' ', array_pop($parts)));
</txp:php>
Offline
Re: Custom Error Page
Thanks for all the help, guys. I think I’ll stick with just the URL — if I’ve manually changed the page’s slug at any point, the URL won’t necessarily be the same as the post title, so converting it in the way I initially described doesn’t really make much sense. (Sorry if anyone wasted any time trying to figure that out.)
All is well now!
Offline
#12 2008-04-15 22:23:19
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Custom Error Page
BTW, shouldn’t a page that used to exist but was deleted return a 410 instead of a 404? But I suppose Textpattern doesn’t handle 410s…
Offline