Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2013-04-26 20:24:51

rossharvey
Member
From: Earth. Sometimes.
Registered: 2005-03-16
Posts: 233
Website

Output all images in a category [Slideshow per post - any better way?]

Evening!

I’m adding a slideshow section to the new website, in which each post will have multiple images.

I’m considering creating a new image category per post, and then iterating through said category and outputting a simple HTML line per image.

Is that possible (or a good idea)?Something along the lines of:

<txp:images section="slideshow" category="gallery" sort="rand">
<a class="rsImg" href="<path to category image>"><txp:title /></a>
</txp:images>

<path to category image>

No idea how to get that bit :)

Or is there an easier method/plugin to achieve the same thing?

Would appreciate some TXP skills!

Offline

#2 2013-04-26 22:18:06

rossharvey
Member
From: Earth. Sometimes.
Registered: 2005-03-16
Posts: 233
Website

Re: Output all images in a category [Slideshow per post - any better way?]

I should have guessed…

http://stefdawson.com/sw/plugins/smd_gallery

Looks like it may do the trick.

Edit: it does indeed. Cheers Stef :¬)

Last edited by rossharvey (2013-04-26 22:43:22)

Offline

#3 2013-04-27 02:02:00

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,477

Re: Output all images in a category [Slideshow per post - any better way?]

rossharvey wrote:

I’m adding a slideshow section to the new website, in which each post will have multiple images.

For the above, you can do it without a plug in. Put in the article image field a comma separated list with the image IDs.

And the code is:

<txp:if_article_image>
	<txp:images sort="rand()" wraptag="ul" class="slider" break="li">
		<txp:image />
	</txp:images>
</txp:if_article_image>

Offline

#4 2013-04-27 08:46:51

rossharvey
Member
From: Earth. Sometimes.
Registered: 2005-03-16
Posts: 233
Website

Re: Output all images in a category [Slideshow per post - any better way?]

Thanks for the code, but that’s a lot of effort when you have 40+ images per slideshow!

Offline

#5 2013-04-27 09:03:21

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

Re: Output all images in a category [Slideshow per post - any better way?]

Take look at the collection of image tags. What you should be interested in are the image_url and image_info.

<txp:images category='issue-<txp:article_id />'>
    <a class="rsImg" href="<txp:image_url />">
        <txp:image_info type="name" />
    </a>
</txp:images>

The above pulls images from a category named after the article ID (e.g. ‘issue-274’), and lists each image’s name linked to the full-sized image.

Last edited by Gocom (2013-04-27 09:04:38)

Offline

#6 2013-04-27 09:10:38

rossharvey
Member
From: Earth. Sometimes.
Registered: 2005-03-16
Posts: 233
Website

Re: Output all images in a category [Slideshow per post - any better way?]

I’ve been adding the image category name to a custom field, and using that dynamically.

Any way your example above can use that custom field name, rather than the article id? I.e.

<txp:images category='<txp:custom_field name="slideshow" />'>
    <a class="rsImg" href="<txp:image_url />"><txp:title /></a>
</txp:images>

As that would be perfect and negate the need for a plugin.

Last edited by rossharvey (2013-04-27 09:10:58)

Offline

#7 2013-04-27 09:20:48

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

Re: Output all images in a category [Slideshow per post - any better way?]

Just change the category attribute’s value to a custom field tag, and throw the code to your article form, or in your article statement you have wrapped between your article tags.

Offline

#8 2013-04-27 09:28:29

rossharvey
Member
From: Earth. Sometimes.
Registered: 2005-03-16
Posts: 233
Website

Re: Output all images in a category [Slideshow per post - any better way?]

Gocom wrote:

Just change the category attribute’s value to a custom field tag, and throw the code to your article form, or in your article statement you have wrapped between your article tags.

Sorry buddy, you lost me there – know as familiar with TXP as yourself…

Any way you can explain that to a coder, but not a TXP coder? :¬)

Offline

#9 2013-04-27 10:39:47

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

Re: Output all images in a category [Slideshow per post - any better way?]

rossharvey wrote:

Any way you can explain that to a coder, but not a TXP coder? :¬)

Think a bit. Do you see the snippet you posted earlier, the one that had the custom_field tag as the category value. Take that and modify the contents to your liking. You have the answer, given by yourself, and the tools, now just hit the rocks together.

<path to category image>

No idea how to get that bit :)

Want to know the secret where I got it? Tag Reference. Yes, me and others that answer questions here, actually read documentation. Its not like we have infinite memory that remembers inconsistent range of tag attributes Textpattern template language has.

Offline

#10 2013-04-27 10:56:49

rossharvey
Member
From: Earth. Sometimes.
Registered: 2005-03-16
Posts: 233
Website

Re: Output all images in a category [Slideshow per post - any better way?]

Believe me buddy, I do try myself – constantly. I had drafted another post here just 10 minutes ago, then went off to try and fix it one last time before commiting – and I did, so the post was trashed.

I only ever commit to the post button if I’m genuinely stuck, and do not treat this forum as an ‘ask-all’ community.

This snippet:

<txp:images category='<txp:custom_field name="slideshow" />'>
    <a class="rsImg" href="<txp:image_url />"><txp:title /></a>
</txp:images>

WAS my attempt at trying to figure it out :¬)

Your own reply seemed to mirror what I’d actually tried to do; change the category attribute to the actual custom field name, hence my confusion.

Offline

#11 2013-04-27 12:58:08

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

Re: Output all images in a category [Slideshow per post - any better way?]

What is the problem with the snippet? What you have there does work. Tho it does list images regardless whether the custom field is populated or not (you may want to wrap that to a if_custom_field), and that is uses the same article title for every image in an article, but the latter seems to be intentional.

If you want to pick a random cover image for the post that links to the article page:

<txp:article>
    <txp:if_custom_field name="foobar">
        <txp:images category='<txp:custom_field name="foobar" />' limit="1" sort="rand()">
            <txp:permlink>
                <img src="<txp:image_url />" />
            </txp:permlink>
        </txp:images>
    </txp:if_custom_field>
</txp:article>

It’s the same code as before, same logic, few tag and attribute changes. If you want to list all images in the category set in foobar field:

<txp:article>
    <txp:if_custom_field name="foobar">
        <txp:images category='<txp:custom_field name="foobar" />' >
            <a href="<txp:image_url />">
                <txp:image_info type="name" />
            </a>
        </txp:images>
    </txp:if_custom_field>
</txp:article>

If you put the code your article form, remove the wrapping article tags, that are there for example purposes. You could also save the code as a misc form template and include that form in your articles, if that is what you want and want to choose where the images appear.

But the code is not intended to be used in your article body. While you can, that’s pain to manage. In general you shouldn’t use templating language in your articles at all. But if you do, remember to escape Textile processing for the code block (with the help of its notextile. tag).

rossharvey wrote:

Believe me buddy, I do try myself – constantly.

Few tips, if you haven’t already;

  • Turn debugging mode on. For instance, the code in your first post would generate notices. There is no sort value ‘rand’, and images doesn’t accept sections.
  • Bookmark Tag Reference. Need an URL to your image? Take look at the ‘image tags’.
  • If you have problems with your templates, post your tag trace. We can only give specific guidance if we know what you have.

Offline

#12 2013-04-27 13:58:35

rossharvey
Member
From: Earth. Sometimes.
Registered: 2005-03-16
Posts: 233
Website

Re: Output all images in a category [Slideshow per post - any better way?]

I’d not tried the snippet at that point, I was asking whether it looked like it would work :¬)

Thanks very much for the tips – all taken on board, and in debug mode as we speak!

Edit: all working – cheers!

Last edited by rossharvey (2013-04-27 14:07:24)

Offline

Board footer

Powered by FluxBB