Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2009-09-16 16:02:02
- Neko
- Member
- Registered: 2004-03-18
- Posts: 458
Select images from categories and link them to an article
I have three image categories and each category contains a few images (10-20 each).
What I’d like to do is to select a few of those images, let’s say 4 random thumbnails from each category, and link them to an URL (URLs have the same name of categories, so category “toys” will have a corresponding article located at example.com/toys).
Basically, the resulting HTML should be like this:
<a href="http://example.com/toys/"><img src="category-toys-1-t.jpg" alt="alt" /></a>
<a href="http://example.com/fudge/"><img src="category-fudge-1-t.jpg" alt="alt" /></a>
and so on.
Is there a way to achieve such result?
Thanks.
Offline
#2 2009-09-16 16:54:08
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Select images from categories and link them to an article
My guess is that a combination of wet_for_each_image and upm_image will do this.
Offline
Re: Select images from categories and link them to an article
Without trying to contradict the Queen of Tags, I would try smd_gallery, and feed it with some tags-in-tags magic.
You will need to create duplicate categories, both for articles and images.
Then, you feed smd_gallery with the category1 (or 2) from current article, which will correspond to one image category.
The “problem” here may be if you need to use categories in articles for another purpose…
But… now that I re-read your post, you say that article URL will match the category name, so you can use the txp:article_url_title to feed smd_gallery and fetch the images for corresponding category…
Offline
Re: Select images from categories and link them to an article
Neko wrote:
<a href="http://example.com/toys/"><img src="category-toys-1-t.jpg" alt="alt" /></a>
Is that a literal image file name, or is category-toys-1-t.jpg
a stand-in for a standard Txp image file name (e.g. 24t.jpg)?
Code is topiary
Offline
#5 2009-09-16 19:29:04
- Neko
- Member
- Registered: 2004-03-18
- Posts: 458
Re: Select images from categories and link them to an article
jsoo wrote:
<a href="http://example.com/toys/"><img src="category-toys-1-t.jpg" alt="alt" /></a>
Is that a literal image file name, or is
category-toys-1-t.jpg
a stand-in for a standard Txp image file name (e.g. 24t.jpg)?
Sorry, I wasn’t clear, it should be 24t.jpg
.
Offline
Re: Select images from categories and link them to an article
Using soo_image you would do something like this for each image category:
<txp:soo_image_select category="toys" sort="random" limit="4">
<a href="/toys"><txp:soo_image thumbnail="1" /></a>
</txp:soo_image_select>
Of course you could make use of category_list
, containing the above code, something like:
<txp:category_list type="image" categories="toys,fudge">
<txp:soo_image_select category='<txp:category />' sort="random" limit="4">
<a href="/<txp:category />"><txp:soo_image thumbnail="1" /></a>
</txp:soo_image_select>
</txp:category_list>
Code is topiary
Offline
#7 2009-09-16 22:44:43
- Neko
- Member
- Registered: 2004-03-18
- Posts: 458
Re: Select images from categories and link them to an article
Well, thanks for all the fantastic tips. :)))
I decided to follow the solution proposed by J and it worked like a charm. Thanks a bunch!
Offline