Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
How do I parse a URL that is stored in a custom field?
Hey,
Over at Posh CSS I currently store the links to the full articles in a custom field:
<txp:custom_field name="fullurl" />
How do I then convert that value from say: http://www.zurb.com/article/305/easily-turn-your-images-into-polaroids-wi
to just zurb.com
for easy display on my site?
I currently have a second field that is titled shorturl, but surely there is a way to convert the original URL using the parse_url function in PHP? I only need the hostname.
My ideal output would be:
<a href="<txp:custom_field name="fullurl" />">***parsed hostname here***</a>
This one is a little over my head, any advice?
Thanks.
Sam Brown
sambrown.me | welovetxp.com
Offline
Re: How do I parse a URL that is stored in a custom field?
Sam wrote:
How do I then convert that value… to just
zurb.com
for easy display on my site
Someone (Gocom?) told me that parse_url()
is quite slow, so a combination of string functions might be quicker; especially in a list situation:
<a href="<txp:custom_field name="fullurl" />">
<txp:php>
$str = custom_field(array('name' => 'fullurl'));
echo substr($str, 0, strpos($str, '/', 8));
</txp:php>
</a>
(untested) but it’ll fail if there’s a URL without any /section/article after it so be careful that your custom fields are all individual articles.
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: How do I parse a URL that is stored in a custom field?
nice and simple, stef.
off-topic: just a heads-up sam. I have tried to reach welovetxp.com on and off over the past few weeks with no luck – it always times out for me (the google cache links too). Is it just me or is it currently down?
edit: your other links in your signature are also unreachable, but PoshCSS is no problem.
Last edited by jakob (2009-10-15 18:02:07)
TXP Builders – finely-crafted code, design and txp
Offline
Re: How do I parse a URL that is stored in a custom field?
Thanks Stef, that helps a lot! :)
Jakob, nope everything is running fine as far as I can tell. Normal to good traffic levels. That said, someone else had problems visiting my personal site. sam.brown.tc, is that the case for you as well?
Could you provide a traceroute to welovetxp.com for me and I’ll submit it to my host.
Sam Brown
sambrown.me | welovetxp.com
Offline
Re: How do I parse a URL that is stored in a custom field?
traceroute duly sent via board email.
TXP Builders – finely-crafted code, design and txp
Offline