Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-01-14 20:17:39

edemay
Member
From: Montréal
Registered: 2005-08-16
Posts: 27
Website

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

#3 2008-01-14 20:21:59

iblastoff
Plugin Author
From: Toronto
Registered: 2006-06-11
Posts: 1,197
Website

Re: Make a list of articles only if they have an article_image

Offline

#4 2008-01-14 23:03:41

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

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

#5 2008-01-14 23:20:21

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,449
Website GitHub

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.

Txp Builders – finely-crafted code, design and Txp

Offline

#6 2008-01-14 23:46:44

edemay
Member
From: Montréal
Registered: 2005-08-16
Posts: 27
Website

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

#8 2008-01-14 23:56:20

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,449
Website GitHub

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.

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

#10 2008-01-15 00:14:49

edemay
Member
From: Montréal
Registered: 2005-08-16
Posts: 27
Website

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

#11 2008-01-15 00:17:19

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,449
Website GitHub

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.

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

Board footer

Powered by FluxBB