Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Why is there no if_article_image conditional tag and can I achieve it?
Just wondering why there isn’t a conditional tag txp:if_article_image and would there be an easy way to achieve it?
I basically want to add an image to all blog posts. If there is no article image assigned to that post I would like to insert a random image.
If there isn’t an available solution I might have to put my article image ids in a custom field. That would be a pain to go back over all my posts and change things.
Any insight appreciated.
Art Rogue – Fine Art Photography
Offline
#2 2008-04-19 23:44:11
- masa
- Member
- From: Asturias, Spain
- Registered: 2005-11-25
- Posts: 1,091
Re: Why is there no if_article_image conditional tag and can I achieve it?
Haven’t tried it with an article image tag, but it sounds like chh_if_data might do the trick.
Offline
Re: Why is there no if_article_image conditional tag and can I achieve it?
That might be the ticket. Thanks. Now I must find a way to output a random image.
Art Rogue – Fine Art Photography
Offline
Re: Why is there no if_article_image conditional tag and can I achieve it?
Wonder if I can use the if_different tag instead?
Art Rogue – Fine Art Photography
Offline
#5 2008-04-20 02:00:46
- rsilletti
- Moderator
- From: Spokane WA
- Registered: 2004-04-28
- Posts: 707
Offline
Re: Why is there no if_article_image conditional tag and can I achieve it?
mattmikulla wrote:
If there is no article image assigned to that post I would like to insert a random image.
Combined with any other conditional to detect the existence or otherwise of an article image, you can also put smd_random_banner into the ‘else’ part to pick a random image for you. I have done this sort of thing before:
<txp:smd_if field="article_image" operator="isnum">
<txp:article_image />
<txp:else />
<txp:smd_random_banner category="rand_pix" match_text="?keywords" compare_to="caption, alt, name" always_display="1" />
</txp:smd_if>
That will display the article image if it’s set or pick a random image from the rand_pix category, favouring ones that have one of your article’s keywords in their alt, caption or name. If it can’t find one it just picks any of them from that category. Incidentally, the next iteration of random_banner is in the final testing phase ready for release in a day or so.
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: Why is there no if_article_image conditional tag and can I achieve it?
Hi mattmikulla
The plugin upm_image has a conditional if_articl_image tag, and a bunch of other useful stuff for managing images.
Offline