Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
[SOLVED] image gallery & article custom
Can I have the cake and eat it too?
Is there a way to have a list of images appear in image id order and have them linked to the articles they belong?
At the moment this page is generated by calling the images in the articles’ custom_fields. The problem is that what appear to be the last 2 publications are actually the 1st and 3rd. I can understand that the list is generated using the article_custom order (the last 2 belonging to the first article) but is there another way with which they could appear chronologically and link to their respective articles?
the code:
<txp:article_custom section="events, participations, about" limit="999">
<txp:smd_gallery id="?pubs_by_others" escape="">
<txp:permlink><img src="<txp:site_url />images/{id}.jpg" width="230" height="{height}" title="{alt}" alt="{alt}" class="grid_6" /></txp:permlink>
<div class="grid_17 prefix_1">{caption}</div>
</txp:smd_gallery>
</txp:article_custom>
> Edited to add: would a variable and rah_repeat do the job?
> changed the title to make it more relevant to the thread as it is developing.
Last edited by colak (2012-08-06 06:58:49)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: [SOLVED] image gallery & article custom
Over 100 views and no suggestions?
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: [SOLVED] image gallery & article custom
I’m not sure I totally get what’s that you’re trying to achive.
How is the “a way to have list of images appear in image id order” request connected to the “but is there another way with which they could appear chronologically and link to their respective articles” request?
Offline
Re: [SOLVED] image gallery & article custom
Hi Julian,
Thanks for the response. Let me see if I can put it more clearly.
At the moment the entries of that page are listed according to article id but I would like them to appear in image id order.the catch is that I would like the images to be linked to articles.
The code posted above links the images to their respective articles but it also sorts them according to the articles’ ‘posted’ time stamp.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: [SOLVED] image gallery & article custom
By “in image id order” you mean, in the (also chronological) order they are displayed in the Content -> Images tab?
Sounds like a task for smd_gallery & smd_query. With smd_gallery you get the list of images ids in (chronological?) order. Then, you loop over that list, and use smd_query to fetch each article, one by one. For that, you use smd_query to create a query which “asks” something like: “bring me the article which has, in the article_image field, this image id associated”.
Does it make sense?
You could even try if you can use article_custom instead of smd_query. As you can fetch/filter articles by a customfield value (customfieldname="value"
), you could try what happens if you do <txp:smd_gallery ...><txp:article_custom article_image="{id}" /></txp:smd_gallery>
.
Offline
Re: [SOLVED] image gallery & article custom
Sounds like a task for smd_gallery & smd_query. With smd_gallery you get the list of images ids in (chronological?) order.
As I’m wrapping article_custom on smd_gallery, the chronological order i get is that of articles and not that of images as some articles have more than one image.
Then, you loop over that list, and use smd_query to fetch each article, one by one. For that, you use smd_query to create a query which “asks” something like: “bring me the article which has, in the article_image field, this image id associated”.
yes! except I’m using custom_fields. I will try this as it might work! Thanks soo much for your input.
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: [SOLVED] image gallery & article custom
I’m now wondering if I can do it without any plugins…
This does not work but I think that I might be in the right track…
<txp:variable name="otherpubs"
value='<txp:article_custom section="events, participations, about" limit="999" break=",">
<txp:if_custom_field name="pubs_by_others">
<txp:custom_field name="pubs_by_others" />
</txp:if_custom_field>
</txp:article_custom>' />
<txp:if_variable name="otherpubs">
<txp:images id='<txp:variable name="otherpubs" />' sort="id desc" limit="999">
<div class="line">
<txp:article_custom limit="1"> <txp:hide>This does not work as it understandably returns the same article url for all images</txp:hide>
<txp:permlink>
<img src="<txp:site_url />images/<txp:image_info type="id" /><txp:image_info type="ext" />"
alt="<txp:image_info type="alt" />"
title="<txp:image_info type="alt" />"
width="<txp:image_info type="w" />"
height="<txp:image_info type="h" />" class="grid_6" />
</txp:permlink>
</txp:article_custom>
<div class="grid_17 prefix_1"><txp:image_info type="caption" escape="" /></div>
<div class="clear"> </div>
</div>
</txp:images>
</txp:if_variable>
Last edited by colak (2012-08-05 10:03:36)
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: [SOLVED] image gallery & article custom
What if you change this:
<txp:article_custom limit="1">
To this:
<txp:article_custom pubs_by_others='<txp:image_info type="id" />'>
Could that work?
Offline
Re: [SOLVED] image gallery & article custom
maniqui wrote:
Could that work?
That will only work if the field contains a one, single image ID. If it contains comma-separated list of images, it will not find the corresponding article.
If that is the case and the field does contain just a one image ID, then you could just merely sort by the custom field. No other magic would be required in that case, it would give you the ID order. E.g.
<txp:article_custom pubs_by_others="_%" sort="custom_1 desc" limit="9999">
<!--
I'm in ID order (if there is just an image per article).
-->
</txp:article_custom>
Where in the custom_1
is the custom field’s field name / associative ID. The pubs_by_others="_%"
makes sure that custom field isn’t empty. The _
and the %
are both wildcards. A _
matches exactly one character, and a %
zero or more characters.
Offline
Re: [SOLVED] image gallery & article custom
@Julián
No:(
it works like Jukka described meaning that it does not work.
@ Jukka
we have from 0-3 image ids/page currently
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: [SOLVED] image gallery & article custom
Well, back to a possible smd_gallery (maybe txp:images is good enough) & smd_query solution:
Use smd_gallery/txp:image to loop over a list of image ids in in the desired order (id descending, or chronological, that’s up to you), wrapping smd_query.
<txp:smd_gallery ...>
<txp:smd_query column="*" table="textpattern" break=""
where='
custom_1 LIKE "{id}"
OR custom_1 LIKE "%,{id},%"
OR custom_1 LIKE "%,{id}"
OR custom_1 LIKE "{id},%"
AND status=4'
>
... your article tags here:
</txp:smd_query>
</txp:smd_gallery>
Two things to consider:
- this isn’t just one-query-to-fetch-them-all, but one query for each image (i.e. each time smd_gallery loops). Eventually, you may want to cache the output (aks_cache is good for this).
- you may get articles twice or thrice (for those that have more than one image assigned). I can think of a few ways to filter out the duplicates, but firt let’s see if this approach works. At least, until Jukka comes back with some genius, one-liner solution :)
Offline
Re: [SOLVED] image gallery & article custom
maniqui wrote:
this isn’t just one-query-to-fetch-them-all, but one query for each image (i.e. each time smd_gallery loops). Eventually, you may want to cache the output (aks_cache is good for this).
I’m wondering if this is worth it. I might as well hard-code the images on the page. What do you think?
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline