Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-06-04 01:04:04

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Confused by txp:images tag

I’ve got a form:

<txp:article>
	<txp:images><txp:image width="0" height="0" /></txp:images>
	<txp:body />
</txp:article>

and for each article, the following happens:

  • if the article has image IDs in the “Article image” field, those images are displayed with that article
  • if the “Article image” field is blank, all images in the database are displayed with that article

So, two questions:

  1. if the <txp:images> tag is in article context mode, why is it reverting to “all images in the database”, just because an article has no image associated?
  2. how can I output a list of articles, that may or may not have images associated, using standard tags?

Apologies if I’m missing the obvious … it’s been a long week.

P.S. auto_detect="article" doesn’t help either.

Offline

#2 2011-06-04 01:14:49

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: Confused by txp:images tag

Like I said, it’s been long week …

<txp:article_image width="0" height="0" />

… does the job.

But if I was using <txp:image_info>, which can only be used inside <txp:images>, – the above questions still stand.

Offline

#3 2011-06-04 09:43:49

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

Re: Confused by txp:images tag

gomedia wrote:

if the <txp:images> tag is in article context mode, why is it reverting to “all images in the database”, just because an article has no image associated?

Short answer: because it does :-)

Long answer: originally it did behave in the ‘correct’ (imho) way, but it was inconsistent with all the other ‘list’ tags which behave in this, somewhat erroneous, manner. Thus it was changed before release.

how can I output a list of articles, that may or may not have images associated, using standard tags?

Wrap the images tag in <txp:if_article_image> ?


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

#4 2011-06-04 10:27:41

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: Confused by txp:images tag

Thanks for the reply Stef.

Bloke wrote:

Long answer: originally it did behave in the ‘correct’ (imho) way, but it was inconsistent with all the other ‘list’ tags which behave in this, somewhat erroneous, manner. Thus it was changed before release.

Oh dear, two steps forward, one step back … thank goodness <txp:article> doesn’t behave in this manner!

Wrap the images tag in <txp:if_article_image> ?

Or turn <txp:article_image> into a container tag?

So the default position of auto_detect="article" is actually auto_detect="article or baboom!" as well?

I wonder of the Titanic (soo_image) has sunk yet?

Offline

#5 2012-09-19 17:36:09

photonomad
Member
Registered: 2005-09-10
Posts: 290
Website

Re: Confused by txp:images tag

So, if I understand correctly, there is no way (with native txp tags) to output photos from the article_image field for each article IF they are are assigned to a specific image category?

I was hoping the code below would work, but it only repeats all of the site’s images with the “homeshow” category for each article (using Txp 4.5.1):

<txp:article_custom section="art" limit="999" sort="rand()">
<txp:images category="homeshow" auto_detect="article" break="" sort="rand()">
  <p>
    <a href="<txp:permlink />" title="Click for this gallery"><img src="<txp:image_url />" alt="<txp:image_info type="alt" />" /></a>
  </p>
</txp:images>
</txp:article_custom>

EDIT: I guess my bigger question is how to do this if not with native tags? I’m stumped.

Last edited by photonomad (2012-09-19 17:43:50)

Offline

#6 2012-09-19 18:30:10

etc
Developer
Registered: 2010-11-11
Posts: 5,397
Website GitHub

Re: Confused by txp:images tag

I guess wrongly @auto_detect=“article”@ works only within <txp:article />. You can try to extract article images from $thisarticle (not tested):

<txp:article_custom section="art" limit="999" sort="rand()">
<txp:images category="homeshow" id='<txp:php>global $thisarticle; echo $thisarticle["article_image"];</txp:php>' break="" sort="rand()">
  <p>
    <a href="<txp:permlink />" title="Click for this gallery"><img src="<txp:image_url />" alt="<txp:image_info type="alt" />" /></a>
  </p>
</txp:images>
</txp:article_custom>

Last edited by etc (2012-09-19 19:26:09)

Offline

#7 2012-09-19 18:37:45

photonomad
Member
Registered: 2005-09-10
Posts: 290
Website

Re: Confused by txp:images tag

etc, thanks! Your solution works and I am going to use it because it doesn’t involve a plugin!

However, in the time between my question and your answer, I figured out how to do it with smd_if as well. Here’s the code for anyone curious:

<txp:variable name="homeshow" value='<txp:images category="homeshow" break="/"><txp:image_info type="id" /></txp:images>' />
<txp:article_custom section="art" limit="999" sort="rand()">
<txp:images auto_detect="article" break="" sort="rand()">
<txp:variable name="current_img" value='<txp:image_info type="id" />' />
<txp:smd_if field="txpvar:current_img" operator="in" value="txpvar:homeshow">
  <p>
    <a href="<txp:permlink />" title="Click for this gallery"><img src="<txp:image_url />" alt="<txp:image_info type="alt" />" /></a>
  </p>
<txp:else />
</txp:smd_if>
</txp:images>
</txp:article_custom>

Offline

#8 2012-09-19 18:41:24

photonomad
Member
Registered: 2005-09-10
Posts: 290
Website

Re: Confused by txp:images tag

I just tried substituting <txp:images break=","><txp:image_info type="id" /></txp:images> in place of <txp:php>global $thisarticle; echo $thisarticle["article_image"];</txp:php> in etc’s code above and it works too.

<txp:article_custom section="art" limit="999" sort="rand()">
<txp:images category="homeshow" id='<txp:images break=","><txp:image_info type="id" /></txp:images>' break="" sort="rand()">
  <p>
    <a href="<txp:permlink />" title="Click for this gallery"><img src="<txp:image_url />" alt="<txp:image_info type="alt" />" /></a>
  </p>
</txp:images>
</txp:article_custom>

Offline

#9 2012-09-19 18:57:30

etc
Developer
Registered: 2010-11-11
Posts: 5,397
Website GitHub

Re: Confused by txp:images tag

<txp:custom_field name="article_image" /> will work too, though some call it hack :)

Offline

Board footer

Powered by FluxBB