Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Re: Output sticky articles first in an article list
And it’s finally working with the solution provided by Jeff and the upm_article_image plugin
Like this:
<txp:if_article_list>
<!-- We are in an article list context -->
<!-- Step: 1 -->
<!-- Is there a sticky article in this list ? -->
<!-- Build a variable that tries to output any found sticky article -->
<txp:variable name="stickit"><txp:article status="sticky" limit="1">dummy text</txp:article></txp:variable>
<txp:if_variable name="stickit" value="">
<!-- There's no sticky article ! Just fire the first live article found -->
<!-- Step: 2 -->
<!-- Does the article have an image associated ? -->
<txp:variable name="art_img" value="" /> <!-- Edit: need to initialize the variable -->
<!-- Let's try over the next 5 articles to check if at least 1 has an image associated -->
<txp:article limit="5">
<txp:if_variable name="art_img" value="">
<txp:if_article_image>
<!-- If an article with an image is found display the article details -->
<txp:title />
<txp:body />
<txp:upm_article_image form="image_details">
<txp:variable name="art_img" value="1" />
</txp:if_article_image>
</txp:if_variable>
</txp:article>
<txp:else />
<!-- We have a Sticky article, just display it -->
<txp:article status="sticky" limit="1">
<txp:title />
<txp:body />
</txp:article>
</txp:if_variable>
</txp:if_article_list>
Now for the fine folks jumping to the end of this thread the above will do this, in an article list context:
1- If there’s a Sticky article display it first.
2- If not, display a live article that has an image.
3- If no image associated with the article, skip to the next article that has an image.
Et voilà !
Thanks a lot: Julian, Jsoo, Els… Any details to add to the code above ? Comments ?
Well I guess code is like Lasagna, it tastes better the day after you cooked it…
Thank you very much folks for the fine cooking advices !
:)
Last edited by hablablow (2010-12-10 16:55:23)
_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__
Offline
Re: Output sticky articles first in an article list
You’ll need an article status="sticky" limit="1"
tag surrounding the title
and body
in your else
block.
Code is topiary
Offline
Re: Output sticky articles first in an article list
Corrected Jeff. Thanks again for your help, much appreciated !
_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__
Offline
Re: Output sticky articles first in an article list
Gillaume, can you send this over to TXP Tips?
Offline
Re: Output sticky articles first in an article list
I’m on it Jonathan. I’m going to split it in two since it covers 2 different topics.
_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__
Offline
Re: Output sticky articles first in an article list
Well, first part of the article was published on Txp Tips here
Last edited by hablablow (2010-12-11 21:53:55)
_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__
Offline
Re: Output sticky articles first in an article list
Second part including your code is here Jeff, on Txp tips.
Again thanks for the help.
Cheers.
Last edited by hablablow (2010-12-13 10:10:29)
_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__
Offline