Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Can I get image id number from a custom field?
Hello guys,
I’m trying to achieve to pull an image id from a custom field, but I don’t have much luck so far.
The code in my article type form:
<p><a href="<txp:permlink />"><txp:image id="<txp:custom_field name="main_page_image" />" /></a></p>
Could it work at all?
If not, how can I implement displaying an image of the article on the home page of a website, but not using article image for this purpose?
Thanks in advance
Offline
#2 2008-09-16 13:29:22
- net-carver
- Archived Plugin Author
- Registered: 2006-03-08
- Posts: 1,648
Re: Can I get image id number from a custom field?
sipke
that code won’t work on anything other than the development version. Is there any reason you can’t use the article image field under advanced options for that article instead — as that would avoid the need to resort to php in your form?
If you want to go with a the custom field you could try this (it’s a brain-dump — not tested)…
<p><a href="<txp:permlink />">
<txp:php>
$atts = array( 'id' => custom_field( array( 'name'=>'main_page_image' ) ) );
echo image( $atts );
</txp:php>
</a></p>
…but I’ve probably overlooked something. Hope that helps.
— Steve
Offline
Re: Can I get image id number from a custom field?
sipke wrote:
how can I implement displaying an image of the article on the home page of a website, but not using article image
Under TXP 4.0.6 and lower, tags-inside-tags don’t work too well (4.0.7 fixes that, yay!)
You will probably need to locate a copy of the plugin asy_wondertag and surround your tag-in-tag with that:
<a href="<txp:permlink />">
<txp:asy_wondertag>
<txp:image id="<txp:custom_field name="main_page_image" />" />
</txp:asy_wondertag>
</a>
EDIT: or net-carver’s solution. Or try the upm_image plugin which might help you approach it from a nother angle (I don’t know, I’ve never used it but have heard great things about it)
Last edited by Bloke (2008-09-16 13:30:52)
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: Can I get image id number from a custom field?
Net-carver and Bloke: many many thanks guys, your recommendations work superb!
I didn’t realize that a tag in an attribute is not the same as giving custom field for html tags :P
Many thanks again, especially for the hyper-quick answers! :)))))
Offline
#5 2008-09-16 13:52:46
- net-carver
- Archived Plugin Author
- Registered: 2006-03-08
- Posts: 1,648
Re: Can I get image id number from a custom field?
sipke
you’re welcome. Bloke’s suggestion about using the wondertag plugin is a better way to do it than the php.
Note to self — wondertag — wondertag — wondertag!
— Steve
Offline