Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2006-09-25 15:28:37
- wcardinal
- Member
- Registered: 2005-07-16
- Posts: 17
txp:php question
I want to take a custom field that has an authors name (ie: “Bob McGood”) and turn it into a url version (ie: “bob-mcgood”) for linking to that authors bio page
I started with something like this, which didn’t work…
<code>
<txp:php>
$str = “(<txp:custom_field name=“Author” />)”;
$str = strtolower($str);
echo $str;
</txp:php>
</code>
<br /><br />
can anyone help?
Last edited by wcardinal (2006-09-25 15:34:22)
Offline
Re: txp:php question
There’s a function somewhere in the txp core that does this for the title url (slug).
But here’s what I’m using in a project I’m working on right now:
<pre><code>
$slug = htmlentities(strtolower(‘Your String or Name or String Variable Here’));
$slug = preg_replace(‘/&([a-zA-Z])(uml|acute|grave|circ|tilde);/’,’$1’,$slug);
$slug = html_entity_decode($slug);
$chrsarr = array(‘!’, ‘?’, ‘#’, ‘$’, ‘%’, ‘^’, ‘&’, ‘*’, ‘(‘, ‘)’, “’”, ‘”’, ‘\\’, ‘|’, ‘>’, ‘<’, ‘,’, ‘.’, ‘/’, ‘`’);
$slug = str_replace($chrsarr, “”, $slug);
$finalslug = str_replace(” “, “-”, $slug);
echo $finalslug;
</code></pre>
Last edited by Walker (2006-09-25 16:20:56)
Offline
Re: txp:php question
Oh, also, I’m certain you can’t put a textpattern tag inside a php block in textpattern and expect it to give you the tag’s data before executing the php.
You need to do something more like <code>$thisarticle[‘author’]</code> but don’t quote me on that. I didn’t look this up anywhere.
Offline
#4 2006-09-25 17:03:25
- wcardinal
- Member
- Registered: 2005-07-16
- Posts: 17
Re: txp:php question
ha – I got it….
<code>
<txp:php>
//Author is the name of my custom field
$str = str_replace(” “, “-”, $thisarticle[‘Author’]);
$str = strtolower($str);
echo $str;
</txp:php>
</code>
thanks for your help!
Last edited by wcardinal (2006-09-25 17:03:46)
Offline
Offline
Pages: 1