Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
[Solved] Extract custom field contents from next and prev articles
Hi, Textpatrons. It’s been a while.
Can I populate an a title
dynamically from a custom field when it’s used with next and prev articles – like this:
<a href="<txp:link_to_next />" title="NEXT CUSTOM FIELD STUFF HERE"><txp:next_title /></a>
<a href="<txp:link_to_prev />" title="PREV CUSTOM FIELD STUFF HERE"><txp:prev_title /></a>
I could perhaps bodge it with an article form, but I’m not aware of a way to use article_custom
with the next and prev articles.
Grateful for any advice on this one. Thanks.
Last edited by gaekwad (2014-03-17 15:03:33)
Offline
Re: [Solved] Extract custom field contents from next and prev articles
Hi Pete,
this might work (untested):
<a href="<txp:link_to_next />" title="<txp:article_custom id='<txp:custom_field name=''next_id'' />' form='your_form' />">
<txp:next_title />
</a>
Offline
Re: [Solved] Extract custom field contents from next and prev articles
Hi, Oleg.
Thank you very much – I’ll test it out. it works!
Last edited by gaekwad (2014-03-17 15:03:12)
Offline
#4 2014-03-17 15:59:19
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,304
Re: [Solved] Extract custom field contents from next and prev articles
I’ve not tried it in many environments and can’t tell whether I’m really right, but as the tag <txp:page_url type="next_id" />
doesn’t impose entering values into custom fields but should work indepentently of any such manual ordering, I think I should propose it anyways. (To be used where Oleg’s <txp:custom_field name=''next_id'' />
sits.)
I should annotate that all the devs said “Use with caution, undocumented, might change any time” whenever this was discussed.
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: [Solved] Extract custom field contents from next and prev articles
Uli – that’s a very good point. Thank you. I’ll switch it now.
Offline
Re: [Solved] Extract custom field contents from next and prev articles
uli wrote #279771:
entering values into custom fields
gaekwad wrote #279772:
Uli – that’s a very good point. Thank you. I’ll switch it now.
Guys, I would never suggest such an oddity as creating a custom field named next_id
for that. Textpattern automatically populates articles internal next_id
and prev_id
fields when you call <txp:link_to_next/prev />
, and <txp:custom_field />
can extract any article data, not only “official” custom fields. But this is undocumented, as you say.
Offline
Re: [Solved] Extract custom field contents from next and prev articles
Oleg, I can’t speak for Uli but I knew what you were referring to when you used custom field in the context you did, so there’s no confusion or misunderstanding here. It was Stef who first introduced the idea of a custom field hack to me here and I was acutely aware it might disappear in future releases, so I tend to avoid where possible.
Interesting point regarding page_url
, though: there is no reference to next_id
or prev_id
on the docs wiki page_url article – does that, by definition, make it undocumented? According to the wiki search, there is no reference to next_id
or prev_id
at all:
http://www.textpattern.net/wiki/index.php?search=prev_id&go=Go
http://www.textpattern.net/wiki/index.php?search=next_id&go=Go
Offline
#8 2014-03-17 17:09:03
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,304
Re: [Solved] Extract custom field contents from next and prev articles
Pete, here’s more or less an answer to everything you’re referring to :)
Edit: Re “might disappear in future”: If I’m not mistaken, Oleg’s code is not a custom field hack, to my understanding he assumes you’ve set up a cf named “next_id”, so no hidden/undocumented/exploited cf in use, hence more future proof than my proposal. The cf’s name is just unusually wrapped in duplicated single quotes.
Last edited by uli (2014-03-17 17:31:05)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: [Solved] Extract custom field contents from next and prev articles
Thanks, Uli.
Offline
Re: [Solved] Extract custom field contents from next and prev articles
uli wrote #279775:
If I’m not mistaken, Oleg’s code is not a custom field hack, to my understanding he assumes you’ve set up a cf named “next_id”
No, Uli, absolutely no custom field is involved here. Some function called by <txp:link_to_next />
sets $thisarticle['next_id']
value, that is retrieved later by <txp:custom_field name="next_id" />
. And I don’t think $pretext['next_id']
(used by <txp:page_url />
is set, at least according to my txp bible.
Offline
#11 2014-03-17 21:48:02
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,304
Re: [Solved] Extract custom field contents from next and prev articles
Wo… huhh?!?? (What’s the emoticon for “jaw dropped”?)
etc wrote #279782:
sets
$thisarticle['next_id']
value
… which is a variable, isn’t it? Which then can be retrieved by a custom field tag? Is that what you said?
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: [Solved] Extract custom field contents from next and prev articles
uli wrote #279785:
What’s the emoticon for “jaw dropped”?
Officially :-C
… which is a variable, isn’t it? Which then can be retrieved by a custom field tag?
Yes, once retrieved from the db, all article data (title, body, …) is temporary stored by txp in a variable array called $thisarticle
($thisarticle['body'],$thisarticle['custom_1']
, …). Some tags or plugins add to this array their own data, e.g. $thisarticle['next_id']
. The <txp:custom_field name="some_name" />
tag simply retrieves the value of $thisarticle['some_name']
, eventually transforming some_name
into custom_n
when appropriate. Note however, that some_name
has not to be a cf name, <txp:custom_field name="article_image" />
works as well.
Offline