Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#133 2010-11-16 09:36:21

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

Re: Images are 1st class citizens of TXP

damienbuckley wrote:

Unless I’m using it wrong, ‘offset’ doesn’t work. Limit works fine

Odd, it seems to work for me unless I don’t understand what you’re trying to do. Here’s what I did:

  1. In an article, set the Article Image field to 20, 2, 4, 5, 3 which correspond to 5 images I have, across various categories
  2. Put this code in the article body: <txp:images limit="3" offset="0"><txp:thumbnail /><txp:image_info type="name" /></txp:images>
  3. When viewing the article I see 3 thumbs, seemingly ordered by name
  4. Adjusting the tag to offset="1" and refreshing skips the first image
  5. Similarly, using offset="2" and so forth moves the selection on by one image each time
  6. Adjusting limit reduces the number of images in the result set, and offset still applies correctly
  7. If I add sort="id" then it dutifully sorts them in the order 2, 3, 4, 5, 20 and offset skips them in that order

What am I missing?

EDIT: if you want to maintain the order of the article image field you can try this trick.

Last edited by Bloke (2010-11-16 09:41:40)


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

#134 2011-02-28 09:48:53

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 859
Website

Re: Images are 1st class citizens of TXP

Just a couple of quick clarification needed here, using this code, I would have thought that it would display the first image in the article image field;

<txp:images thumbnail="1" limit="1" form="slir-120" auto_detect="article" />

I was using this in the form:

<img src="<txp:image_url thumbnail="1" />" alt="<txp:image_info type="alt" />" />

in the but to make it work I needed to use some of stefs cunning magic and add the id field

<img src="<txp:image_url id='<txp:custom_field name="article_image" />' thumbnail="1" />" alt="<txp:image_info id='<txp:custom_field name="article_image" />' type="alt" />" />

Should my first attempt worked or am I missing something?

Offline

#135 2011-02-28 10:40:44

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

Re: Images are 1st class citizens of TXP

tye wrote:

I would have thought that it would display the first image in the article image field

No. Once you use any of the filtering attributes such as id, name, category, author, realname, extension or thumbnail you are telling the tag that is your “list” of images. It therefore ignores the article image (regardless of what you set auto_detect to) because you are explicitly telling it which images you want to see; in this case, all images that have a thumbnail (EDIT: you can prove this by removing the limit: you’ll see every image that has a thumbnail)

Your <txp:images> tag almost becomes redundant when you add the id to the tags in your form because you are telling them to use that particular image, which is why it “works”. But you might as well have used <txp:output_form form="slir-120" /> or just pasted your form contents in place of your <txp:images> tag.

So if you want the article image to be your ‘list’ of images you need to remove thumbnail="1" from the <txp:images> tag (and you can remove auto_detect as well, since it’s implied by default). If you then only want to display the image if it has a thumbnail you can use <txp:if_thumbnail> in your form.

Does that help?

Last edited by Bloke (2011-02-28 10:42:23)


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

#136 2011-02-28 22:40:03

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 859
Website

Re: Images are 1st class citizens of TXP

Thanks Stef – I see now, I was actually over complicating things with my forms, duplicating items unnecessarily.

It was actually much more simpler – I now have this:

<txp:images form="slir-120" />

and this

<img src="<txp:image_url />" thumbnail="1" alt="<txp:image_info type="alt" />" />

Works great – I was just thinking it must be harder :)

Offline

#137 2011-02-28 23:15:44

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

Re: Images are 1st class citizens of TXP

thumbnail="1" wouldn’t be doing anything there since it’s in a HTML tag and not a TXP tag. I think you want

<img src="<txp:image_url thumbnail='1' />" alt="<txp:image_info type="alt" />" />

Last edited by MattD (2011-02-28 23:18:20)


My Plugins

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

Offline

#138 2011-03-01 00:28:25

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 859
Website

Re: Images are 1st class citizens of TXP

Thanks MattD – that was my copying error :)

Offline

#139 2011-03-18 13:45:59

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 859
Website

Re: Images are 1st class citizens of TXP

OK – got another one here – it could be because I am tired at the moment – but basically the first txp:images tag should only show one image from the article_image field in order, the second should show the the other images, offsetting the first – but it isn’t working unless I add a limit=“any number” – not sure if this is a bug, or the way it should work, or even if it is worth mentioning :):

<txp:images form="comp-gallery" wraptag="ol" break="li" class="adopted-gallery" limit="1" sort='FIELD(ID,<txp:custom_field name="article_image" />)' />
<txp:images form="adopted-gallery" wraptag="ol" break="li" class="adopted-gallery" offset="1" sort='FIELD(ID,<txp:custom_field name="article_image" />)' />

Offline

#140 2011-03-18 14:10:48

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 999
Website

Re: Images are 1st class citizens of TXP

That’s the way it is expected to work. Set a limit in order to have an offset.

Offline

#141 2011-03-18 15:10:17

TheEric
Plugin Author
From: Wyoming
Registered: 2004-09-17
Posts: 566

Re: Images are 1st class citizens of TXP

Bloke – Think Gallery.

Album -> Thumbnails -> Commenting on full-size images.

This is your task. Go forth, produce.

Offline

#142 2011-03-21 01:14:45

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 859
Website

Re: Images are 1st class citizens of TXP

johnstephens wrote:

That’s the way it is expected to work. Set a limit in order to have an offset.

Really – thanks :) Another thing I’ve never come across :)

Offline

#143 2011-03-21 02:00:42

lazlo
Member
Registered: 2004-02-24
Posts: 110

Re: Images are 1st class citizens of TXP

Hey Bloke
I am trying to simplify my images using the new tag and resizing capabilities of 4.3 but have come across a stumble trying to get Article Image to match my easiest workflow.
I have uniquely named (9780889226548.jpg) images based on ISBN 13 (Book ISBN’s). So to make my life easier I directly linked them to a custom field call in the article image field. I tell the user to drop the jpg in the image folder and everything works.

Article Image Field=[../images/<txp:custom_field name=“ISBN-13” />.jpg]

The problem with this is that I can’t use the image tag because these images don’t go through the image upload, no ID, no NAME, if only there was a URL attribute of the image tag.

<txp:image url=”../images/<txp:custom_field name=“ISBN-13” />.jpg” /> then I could take advantage of on the fly resizing. But no go.

So ok I will use the image uploader. This would work out great if I could custom choose the ID of the image and make it match my custom ISBN-13. I know the name will match the ISBN-13 but the article image field only accepts ID, or URL’s as valid code.

Article Image=[<txp:custom_field name=“ISBN-13” />.jpg] but no go unless you no of an easy way for Image ID to match the Image NAME.

Because I deal with hundreds of books and articles at a time, this is a problem for me and not for most.

So this may be a feature request:

Can the Article Image Field reference Image NAME as well as ID and URL or can the Image tag have an URL attribute?

Cheers
L

Offline

#144 2011-03-21 11:09:07

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

Re: Images are 1st class citizens of TXP

lazlo wrote:

Can the Article Image Field reference Image NAME?

Yes. Sort of. If you only ever have one ISBN per article, and one image per article (discount smd_thumbnail: that could still access multiple thumbs from a single entity in a single field) then you can approach it in one of two ways. They’re both identical really, it just depends on your workflow.

With the ISBN in a custom field, try this:

<txp:images name='<txp:custom_field name="ISBN-13" />.jpg'>
  <txp:thumbnail />
</txp:images>

The <txp:images /> tag builds you a “gallery” of one image based on the name in the custom field. It would do the same thing if you had a comma-separated list of image names but that would mean you would have to add the .jpg to each value in the ISBN-13 field (yuk) or do some cunning stuff to iterate over each value in there, add .jpg to the end of each, maybe stash the result in a txp:variable to save your sanity and then squirt that into txp:images. Not impossible, just more involved and probably relying on a plugin like rah_repeat.

The other approach is the same gravy but using the article image field to hold the image name and using this custom_field trick:

<txp:images name='<txp:custom_field name="article_image" />.jpg'>
   <txp:thumbnail />
</txp:images>

In both cases you can put any image / thumbnail / image_info / image_url / image_author / plugin tag (e.g. smd_thumbnail) in the container to perform your nefarious image-related bidding.

Hope that helps.

Last edited by Bloke (2011-03-21 11:10:51)


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