Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-11-14 10:03:18

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

test for presence of article image

I always imagined/assumed there was a tag called <txp:if_article_image />, until I needed to use it, when I found it didn’t exist!

Seems pretty simple, but how exactly do you test for a value in the Article image field? I’ve used chh_if_data in previous situations, but that one wont work in the current context. Is there something more specific?

cheers
Stu

Offline

#2 2006-11-14 10:53:16

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,323
Website Mastodon

Re: test for presence of article image

What is the context chh_if_data won’t work in?

Offline

#3 2006-11-14 11:02:44

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: test for presence of article image

hi Wet

I want to set a class on the containing element when an image is present. This works

<li class=”<txp:zem_nth step=2 of=2>alternate </txp:zem_nth>clearfix<txp:chh_if_data> hasthumb”> <txp:upm_article_image type=“thumb” /><txp:else />

But I also want to make the image a link, like this, but the tags in the URL mean that chh_if_data is always true, so the else will never be parsed

<li class=”<txp:zem_nth step=2 of=2>alternate </txp:zem_nth>clearfix<txp:chh_if_data> hasthumb”> <a href=”/<txp:section />/<txp:category1 />/<txp:url_title />” title=“full info &amp; mp3”><txp:upm_article_image type=“thumb” /></a><txp:else />

chh_if_data is really useful most of the time, but I occasionally run into a situation like this where I can’t figure out how to stop it being true in all cases

Offline

#4 2006-11-14 11:15:15

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,323
Website Mastodon

Re: test for presence of article image

I am happy with my own plugin in such cases:

<txp:chh_if_data><txp:wet_article_thumb class="foo" /></txp:chh_if_data>

Maybe this works for you as well, as the link to the article is included inside the plugin, for free. Get it while supply lasts!

Offline

#5 2006-11-14 11:41:15

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: test for presence of article image

cheers Wet
that stops the if_data problem

I need to try and generate the custom URL though – <a href=”/<txp:section />/<txp:category1 />/<txp:url_title />” rather than the default Txp permlink, which is the equivalent of <a href=”/<txp:section />/<txp:url_title />”.

Is it possible to add the category1 bit by hacking your plugin? I’m a php baby so any suggestions much appreciated ;)

Offline

#6 2006-11-14 12:09:04

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,323
Website Mastodon

Re: test for presence of article image

Find this line in the plugin’s code almost at the end:

return '<a href="'.permlinkurl_id($thisarticle['thisid']).'" title="'.$title.'">'.join(' ',$out).'</a>';

and replace it with this line:

return '<a href="/'.$thisarticle['section'].'/'.$thisarticle['category1'].'/'.$thisarticle['url_title'].'" title="'.$title.'">'.join(' ',$out).'</a>';

This is the only line in the whole mess which contributes to the article link, so it’s rather simple to build any URL you can imagine.

Offline

#7 2006-11-14 12:10:52

pieman
Member
From: Bristol, UK
Registered: 2005-09-22
Posts: 491
Website

Re: test for presence of article image

sir, you are a gent!
and I am a very happy bunny :)

ps.
for anyone else who might find this useful, there was a lil typo in there
return '<a href="/'.$thisarticle['section'].'/'.$thisarticle['category1'].'/'.$thisarticle['url_title'].' title="'.$title.'">'.join(' ',$out).'</a>';
should be
return '<a href="/'.$thisarticle['section'].'/'.$thisarticle['category1'].'/'.$thisarticle['url_title'].'" title="'.$title.'">'.join(' ',$out).'</a>';

Offline

Board footer

Powered by FluxBB