Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2015-06-23 08:26:48
- raminrahimi
- Member
- From: India
- Registered: 2013-03-19
- Posts: 276
how to assign multiple title for one image
i have three sections (English, Arabic, French)
i configured to display image + title like this on the page:
<txp:images category="gallery" limit="30">
<img src="<txp:site_url />images/<txp:image_info type="id" /><txp:image_info type="ext" />" /></a>
<p><txp:image_info type="caption" /></p>
</txp:images>
but i need any technique to display different title in the different section, example:
for english section: this is a boy
for Arabic section: هذا هو صبي
for French section: ceci est un garçon
is it possible ?
Offline
Re: how to assign multiple title for one image
raminrahimi wrote #291851:
i need any technique to display different title in the different section
If your captions aren’t too long, how about storing them all in a single caption, in a delimited format, e.g.:
Caption field: this is a boy|هذا هو صبي|ceci est un garçon
Then you can put this on your page template, somewhere near the top:
<txp:variable name="langOffset">
<txp:if_section name="en">0</txp:if_section>
<txp:if_section name="ar">1</txp:if_section>
<txp:if_section name="fr">2</txp:if_section>
</txp:variable>
That sets a <txp:variable>
up which determines which offset to use: 0 for English, 1 for Arabic, 2 for French. Change the section names to match your own setup.
If you then employ a split/repeat plugin (such as rah_repeat, or smd_wrap) you can pull out just the one you’re interested in for the current section:
<txp:images category="gallery" limit="30">
<a href="<txp:image_url />"><txp:image /></a>
<p><txp:rah_repeat delimiter="|" value='<txp:image_info />' limit="1" offset='<txp:variable name="langOffset" />'><txp:rah_repeat_value /></txp:rah_repeat></p>
</txp:images>
It’s not exactly pretty, but it’ll work. You may need some defensive code after the <txp:variable>
assignment to default to 0
if it’s not set for some reason. Otherwise you’ll get a warning when trying use the variable. You may also need to check if the caption is indeed delimited first, in case someone has forgotten to do it. In that case you can just output it verbatim.
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
Re: how to assign multiple title for one image
You also could structure your captions:
<p lang='ar'>هذا هو صبي</p>
<p lang='fr'>ceci est un garçon</p>
<p lang='en'>this is a boy</p>
and hide all but one paragraph:
<txp:images category="gallery" limit="30">
<a><img src="<txp:site_url />images/<txp:image_info type="id" /><txp:image_info type="ext" />" /></a>
<txp:image_info type="caption" escape="" />
</txp:images>
<style>
p[lang] {display:none}
p[lang='<txp:section />'] {display:block}
</style>
Another option is to extract from thus structured caption the needed paragraph:
<txp:images category="gallery" limit="30">
<a><img src="<txp:site_url />images/<txp:image_info type="id" /><txp:image_info type="ext" />" /></a>
<txp:etc_query data='<txp:image_info type="caption" escape="" />'
query='p[@lang="<txp:section />" or @lang="en"]' limit="1" />
</txp:images>
This selects the English caption (should be the last paragraph) if no translation is available.
Offline
#4 2015-06-23 14:03:49
- raminrahimi
- Member
- From: India
- Registered: 2013-03-19
- Posts: 276
Re: how to assign multiple title for one image
Hi etc
that’s good option, but if we upload 100 images per day or more, it’s hard to write manually for each image !
any good and dynamic way plz ?
——————————————————————————
let me try the Bloke technique …
Offline
Re: how to assign multiple title for one image
raminrahimi wrote #291879:
if we upload 100 images per day or more, it’s hard to write manually for each image !
any good and dynamic way plz ?
Yes, but otherwise you’ll have to always respect some language order. OK, if you store them as this is a boy|هذا هو صبي|ceci est un garçon
, call
<txp:etc_query query='1+("<txp:section />"="ar")+2*("<txp:section />"="fr")' name="sindex" />
<txp:images category="gallery" limit="30">
<a><img src="<txp:site_url />images/<txp:image_info type="id" /><txp:image_info type="ext" />" /></a>
<txp:etc_query data="<p>{?caption||str_replace(|,</p><p>,$)}</p>" argsep=","
query="p[1+({?sindex}-1)*({?sindex}<=last())]" />
</txp:images>
Last edited by etc (2015-06-24 20:42:59)
Offline
Re: how to assign multiple title for one image
etc wrote #291948:
Yes, but otherwise you’ll have to always respect some language order.
etc is right, marking them up is less prone to error than adopting a convention and hoping people stick to it. But it’s more work to type in, and takes up more space in the limited 255 chars available in that field. Ultimately it’s up to you based on your site content and administrators.
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