Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-04-15 14:55:14

nostrich
New Member
Registered: 2008-04-15
Posts: 4
Website

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

#2 2008-04-15 15:40:52

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,091
Website GitHub Mastodon Twitter

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

#4 2008-04-15 18:28:01

keith
Member
From: Blyth, Northumberland, England
Registered: 2004-12-08
Posts: 199
Website

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

#6 2008-04-15 18:51:57

keith
Member
From: Blyth, Northumberland, England
Registered: 2004-12-08
Posts: 199
Website

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

#7 2008-04-15 20:08:03

thebombsite
Archived Plugin Author
From: Exmouth, England
Registered: 2004-08-24
Posts: 3,251
Website

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

#8 2008-04-15 20:17:29

nostrich
New Member
Registered: 2008-04-15
Posts: 4
Website

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

#9 2008-04-15 20:33:06

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,450
Website GitHub

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

#10 2008-04-15 20:56:27

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

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

#11 2008-04-15 21:15:20

nostrich
New Member
Registered: 2008-04-15
Posts: 4
Website

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

Board footer

Powered by FluxBB