Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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
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:
- Use a custom field to set the image. Provides all the custom field’s filtering power.
- 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
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
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
Offline
Re: how to list only articles with article-image?
Offline
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
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
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.
Offline
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
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
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