Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#11 2020-07-07 14:08:04

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,637
Website

Re: Captions with article_image?

etc wrote #324349:

+1

Core is your oyster ;)


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 2020-07-07 14:14:40

etc
Developer
Registered: 2010-11-11
Posts: 3,768
Website

Re: Captions with article_image?

Bloke wrote #324350:

Core is your oyster ;)

July is not a month with ‘r’ :-) Anyway, it would seemingly become just a poor map to <txp:images />.

Offline

#13 2020-07-07 15:23:32

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,313
Website

Re: Captions with article_image?

Bloke wrote #324347:

In this instance, I agree it does appear redundant. Not entirely sure what we can do about this, though. We could make the assumption that if you’re wrapping statements in <txp:if_article_image> that you’re likely to be using the article image inside it.

This is the form post-thumbnail from a project I have been working on.

<txp:evaluate test="images">

<div class="entry__thumb">
    <a href="<txp:permlink />" class="entry__thumb-link">
    <txp:images id='<txp:custom_field name="article_image" />' >
        <img src="<txp:smd_thumbnail type='1x' display='url' />"

        srcset="<txp:smd_thumbnail type='1x' form="img-srcset" /> 1x,
                <txp:smd_thumbnail type='2x' form="img-srcset" /> 2x"

        alt=""
        />
    </txp:images>
    </a>
</div>

</txp:evaluate>

Based on what we’ve been discussing I guess the id='<txp:custom_field name="article_image" />' is unnecessary since Destry’s example worked without specifying anything.

Or I could remove the <txp:images> code entirely and do this in the article form.

<txp:images>
    <txp:output_form form="post-thumbnail" />
</txp:images>

Offline

#14 2020-07-07 15:46:32

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 9,637
Website

Re: Captions with article_image?

michaelkpate wrote #324356:

Based on what we’ve been discussing I guess the id='<txp:custom_field name="article_image" />' is unnecessary since Destry’s example worked without specifying anything.

The answer is… sort of!

If you wrap the entire block, including <txp:evaluate> in <txp:if_article_image> then yes it will work without the id. If, however, you do not wrap the conditional then there’s an outside chance it won’t work. The reason is subtle:

<txp:images> has the auto_detect attribute which defaults to article, category, author. What this means is that – without any other filter attributes to the contrary – it will:

  1. Look first in the article image field, then if it finds none;
  2. Will look in the URL to see if there’s an image-based /category list in use, and if it doesn’t find one of those;
  3. Consider images owned by the author given in the URL /author list, and if it fails to find one of those;
  4. Return all images in the database.

So, if you put your above code on a page that displays an article that has a missing article_image field, you’ll probably get all images displayed. The id guards against that by skipping the auto_detect feature in lieu of you explicit giving the image to fetch.

tl;dr
If you’re dealing with article images, either:

a) wrap the code in <txp:if_article_image> to avoid nasty surprises of retrieving all images by mistake.

b) specify a filter attribute which overrides the automatic detection of context (i.e. author, category, extension, id, name, realname, size, or thumbnail).

Setting auto_detect="" turns off the feature but will still return all images if no image filter attributes are present. You can also set auto_detect to check for stuff in a different order or to only consider some or all of those automatic contexts.

Last edited by Bloke (2020-07-07 15:52:04)


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

Board footer

Powered by FluxBB