Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
show newest article that has some value in custom field
That’s about the problem – how can I show an article that has for example value “1” on the custom1 field and only the newest one?
This is how it’s done now:
there’s a category called notheadline and headline and the user selects headline if he wants that article to be showed and the code snip is <txp:article custom section:news categorie:headline limit:1>
This is a working solution, but pretty confusing for the writers of the articles, so I would love to have it so I could just tell them to put “1” on a custom field if they want it to be headline and if not, then leave it as it is.. this would also leave the second category available for the purpose that it is ment to be.
Offline
Re: show newest article that has some value in custom field
<a href=“http://textpattern.net/wiki/index.php?title=Txp:if_custom_field”><code><txp:if_custom_field name=“headline” val=“1”></code></a><code>your_article_form</txp:if_custom_field></code> in the article form and <code><txp:article limit=“1” /></code> in the page template.
Offline
Re: show newest article that has some value in custom field
Ah, ok great, that did it :)
thanks \o/
Offline
Re: show newest article that has some value in custom field
Well actually, it didn’t quite do it after all…
I’ve got it like this so it should show only the newest article:
<code><txp:article_custom limit=“1” section=“news” sortby=“Posted” sortdir=“desc” listform=“headline” /></code>
on that form named “headline” i’ve got the <code><txp:if_custom_field name=“headline”></code> and everything is ok UNTIL someone posts a new article that does NOT have anything on that field. Then that article is the newest one on section “news” and it won’t be showed, and since <code><txp:article_custom></code> has a limit of 1, the next article won’t be even checked for the headline info :(
I’ve tried this too, which would just show the newest right article since the results with custom_2 values come first.. but this way the Posted-date is ascending which is the wrong way, it shows the oldest :D
<code><txp:article_custom limit=“1” section=“news” sortby=“custom_2” sortdir=“desc” listform=“headline” /></code>
so it should be sortby custom_2 desc, Posted desc, but I can’t get it that way, help..
sortby=“Posted,custom_2” sortdir=“asc” = sorted by date ASC, sorting by custom is all mixed
sortby=“Posted,custom_2” sortdir=“desc” = exactly same as the one above :O
sortby=“custom_2,Posted” sortdir=“desc” = sorted by custom_2 ASC, sort by Posted DESC
sortby=“custom_2,Posted” sortdir=“asc” = sorted by custom_2 ASC, sort by Posted ASC
So how the damn can I get sorted by custom_2 DESC, sort by Posted DESC :D
Last edited by tormu (2005-12-29 14:56:39)
Offline
#5 2005-12-29 17:37:04
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: show newest article that has some value in custom field
<txp:article_custom section="news" sortby="custom_2 desc, Posted" sortdir="desc" limit="1" form="headline" />
Offline
Re: show newest article that has some value in custom field
all I got was the txp wiki and it didn’t say anything about the possibility to put desc there, inside the sortby, but hey, if that works.. one problem less to solve.
Thanks a million, will try that out tomorrow at work :)
EDIT: Yep, works – wohoo :)
Last edited by tormu (2005-12-30 08:59:43)
Offline
#7 2005-12-29 20:41:31
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: show newest article that has some value in custom field
Here’s why. I’ve brought it up on the dev list. I don’t know how it will eventually work out, but at least the devs are aware of it.
Offline