Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-10-09 11:42:21

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 637
Website

how to list only articles with article-image?

Hey how do I list only articles that include an article-image in them please?
what attribute do I use for it in my article_custom tag?

Offline

#2 2009-10-09 12:57:16

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: how to list only articles with article-image?

THE BLUE DRAGON wrote:

what attribute do I use for it in my article_custom tag?

None. But you can:

  1. Use a custom field to set the image. Provides all the custom field’s filtering power.
  2. Or <txp:variable name="article_image" value='<txp:article_image />' /> check inside the article form, which tho is greatly slower (doesn’t filter the SQL, but the end results) and doesn’t work as well as the option one.

Offline

#3 2009-10-09 13:05:20

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 637
Website

Re: how to list only articles with article-image?

that is so strange, because
I can use:

<txp:if_custon_field name="article_image">
some content
<txp:else />
</txp:if_custom_field>

that works great!
so if “article_image” is like a custom field,
why it doesn’t work when I try to use it as an attribute like customfieldname="_%" ?

Offline

#4 2009-10-09 14:16:55

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 637
Website

Re: how to list only articles with article-image?

the problem now is that I got many articles that only some of them include an article image
and I want to show only the latest one with an image (limit=“1” + Posted desc)
some thing like this:

<txp:article_custom allowoverride=“0” form=“my_form” limit=“1” pgonly=“0” section=“some_section” sort=“Image desc, Posted desc” status=“4” time=“past” />

with this code above (plus the if_custom_field in the form) I’m geting some article that does have an article image,
but it’s not the latest one, it’s somewhere in the middle of 2007.
and I got articles with an image since 2003 till 2009.
O_o

Last edited by THE BLUE DRAGON (2009-10-09 14:57:45)

Offline

#5 2009-10-09 15:14:37

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: how to list only articles with article-image?

soo_article_filter does this.


Code is topiary

Offline

#6 2009-10-09 15:23:22

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 637
Website

Re: how to list only articles with article-image?

jsoo wrote:

soo_article_filter does this.

soo – per!
thanks =)

Offline

#7 2009-10-09 15:43:37

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: how to list only articles with article-image?

Like Gocom said you can do this:

<txp:variable name="article_image" value='<txp:article_image />' />
<txp:if_variable name="article_image" value="">
<!-- No Article Image -->
<txp:else/>
<!-- we have an image -->
</txp:if_variable>

of course doing this you’re parsing through every article returned by your article tag. Not sure if soo_article_filter would be more efficient


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#8 2009-10-09 18:32:43

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,306

Re: how to list only articles with article-image?

What about the straightforward txp:if_article_image I thought, having read that such a function had been added to the core recently. But Textbook still doesn’t have such a page though there’s this function in taghandlers.php:

function if_article_image($atts, $thing='')
	{
	    global $thisarticle;
	    assert_article();

	    return parse(EvalElse($thing, $thisarticle['article_image']));
	}

Maybe someone smarter than me can see through this function and open a wiki page for it?


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#9 2009-10-09 18:47:12

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: how to list only articles with article-image?

The original request is to fetch only those articles that have an article image assigned. That’s why the if_article_image approach won’t work as expected (it will fetch all articles, but only those with an article image will display some output).

It would be nice to add an attribute (article_image="1") to article/article_custom to just fetch those articles that have an image assigned.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#10 2009-10-09 19:46:13

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: how to list only articles with article-image?

Not sure if this helps, but I posted this TXP Tip a few weeks ago when I ran across this problem on a site. Jakob makes a good point in the comment for that article which is worth noting if using the upm_image plugin.

Offline

#11 2009-10-09 19:46:47

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: how to list only articles with article-image?

maniqui wrote:

It would be nice to add an attribute (article_image="1") to article/article_custom to just fetch those articles that have an image assigned.

+1 on that!

Offline

#12 2009-10-09 20:04:30

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: how to list only articles with article-image?

It’s a different task: your tip is for article formatting; the OP’s request is for article selection.


Code is topiary

Offline

Board footer

Powered by FluxBB