Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Make a list of articles only if they have an article_image
Hello all,
I want to make a list of recent articles using a form but only the ones that have an article_image assigned.
- Article_custom is almost there with its customfield=“val” attribute, but an if attribute of the sort doesn’t exist for article_image.
- I looked through all plugins: articles, lists, conditionals, images… to no avail.
Is there a way to hack this? If_different? (i’m only throwing ideas here, i’ve been turning aroundf in circles over this one…)
thanks in advance
Offline
#2 2008-01-14 20:20:39
- els
- Moderator

- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Make a list of articles only if they have an article_image
Try smd_if.
Offline
Re: Make a list of articles only if they have an article_image
http://textpattern.org/plugins/315/tcm_if_article_image
would that work?
Offline
Re: Make a list of articles only if they have an article_image
Els – how can smd_if check if article_image is assigned?
edemay – look through plugin iblastoff posted or look at ras_if_article_image – they are similar.
Here is an example of usage at my site:
<txp:ras_if_article_image>
<div class="image">
<txp:article_image thumbnail="1" />
</div>
<txp:else />
<!-- no image... -->
</txp:ras_if_article_image>
Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?
Offline
Re: Make a list of articles only if they have an article_image
the_ghost wrote:
how can smd_if check if article_image is assigned?
<txp:smd_if field="article_image" operator="isused">
// display it
<txp:else />
// don't
</txp:smd_if>
@edemay : but I’d still go with iblastoff or the_ghost’s suggestion: they’re less resource intensive than smd_if for a single test; not to mention safer (and I just found a bug in the ‘defined’ check – rats!)
Last edited by Bloke (2008-01-14 23:23:08)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: Make a list of articles only if they have an article_image
Hey guys, thanks for the response, unfortunately, it only works half way. I had already tried it with chh_if_data:
in page:
<article_custom section="articles" limit="12" />
form:
<txp:chh_if_data>
<li><txp:permlink><txp:article_image /></txp:permlink></li>
</txp:chh_if_data>
It only outputs the article_images of the last 12 entries (if they exists, so 3 or 8 or 12 if its the case) and not the last 12 entries with article_images. Get the difference? I don’t want to give txp an alternative if its false, it has to display the article_images of the last 12 articles WITH an article_image assigned.
So that’s where i’m at. I feel like the hack has to be done from what the the article_custom calls. That’s why I mentionned the customfieldname="value" attribute of the article_custom tag. It would need a article_image="boolean" attribute. Is there any way to easily do this? (I’m totally php stupid btw).
Last edited by edemay (2008-01-14 23:50:06)
Offline
#7 2008-01-14 23:55:04
- els
- Moderator

- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Make a list of articles only if they have an article_image
chh_if_data doesn’t work in your example (otherwise I would have suggested it to you), because you can only wrap it around one single txp tag. But why wouldn’t one of the abovementioned if_article_image plugins work?
Offline
Re: Make a list of articles only if they have an article_image
edemay wrote:
form:
<txp:chh_if_data>
<li><txp:permlink><txp:article_image /></txp:permlink></li>
</txp:chh_if_data>
Ah, yes, that won’t work because (if I remember correctly) you are testing the result of two tags in that code: txp:permlink and txp:article. Since txp:permlink always returns something (a href=“blah”) the chh_if_data will pass the test!
I would have thought that:
<txp:ras_if_article_image>
<txp:article />
</txp:ras_if_article_image>
would have worked (or tcm_if_article_image of course). Not tested it but that’s how it’s supposed to work!
EDIT: Damn you Els and your lightning finger work. Are you, like, in The Matrix or something?? :-p
Last edited by Bloke (2008-01-14 23:59:26)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
#9 2008-01-15 00:01:32
- els
- Moderator

- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Make a list of articles only if they have an article_image
Bloke wrote:
Damn you Els and your lightning finger work. Are you, like, in The Matrix or something?? :-p
No I just took a typing course when I was still very young and now, finally, it’s paying off :)
Offline
Re: Make a list of articles only if they have an article_image
ok, ok. For the benefit of the doubt, I tried it with ras_if_article_image like you suggested but the result is the same: it only displays 8 images out of the wanted total of 12. Why? Because currently, the article tag calls to display the last 12 articles, THEN to display their article_image if they have one.
What I want, as I mentioned, is to display the article_images of the last 12 articles WITH an article_image assigned. Textpattern might have to go back 20, 40 or 50 articles in the past to display a total of 12 articles that do. Get it?
Last edited by edemay (2008-01-15 00:17:03)
Offline
Re: Make a list of articles only if they have an article_image
Els wrote:
No I just took a typing course when I was still very young and now, finally, it’s paying off :)
OT: Ahhh, genius. I can manage about 70wpm then have to go back and correct 67 of them for typos :-o Even the Mavis Beacon Typing Tutor software got fed up with telling me to “be proud of your success” and instead resorted to frosty silence when I blatantly couldn’t do it. *sigh*
Back on track: ok, sorry edemay I get it now. Yes, a conundrum indeed. article_custom’s limit is getting in the way and truncating your list. Hmmm… let me think…
Last edited by Bloke (2008-01-15 00:19:12)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
#12 2008-01-15 00:27:45
- els
- Moderator

- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Make a list of articles only if they have an article_image
Just an idea: what if you first sort by the article_image field, then sort by date posted? In that case it would display the first 12 articles with an image, right? So:
<txp:article_custom sort="Image desc, Posted desc" limit="12" />
(I am not sure if the image sort should be desc or asc – does it put empty fields first or last? – but you’ll find out soon enough.)
Offline
Re: Make a list of articles only if they have an article_image
Ha! Textpattern is pumping out logic and it’s funny and fun to try and deceipher it all.
Ok here is the roundup: Els, the trick works, but brings in another problem. Obviously. :) But an easy one to fix, fortunately, i don’t use IDs in the article_image field, I use URLs. And the images are name by date like this 20080114blabla.jpg. So I just have to make sure the file’s name, the article_image URL are both the same date as the post and all should be fine. Or else, you get older posts using newer images before, newer posts with older images.
So there. Thanks a bunch guys. If you have some time/brains to spare, i have hanging TXP glitch yet resolved over here.
Offline
#14 2008-01-15 07:49:35
- els
- Moderator

- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Make a list of articles only if they have an article_image
Yes, I see now that the ‘posted desc’ doesn’t do anything here. But you found a good solution!
Offline