Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-05-22 16:05:06

beechy
Member
Registered: 2006-03-02
Posts: 92

Display section of code only when there is a related article

i am using the following to display the related articles

<h2>Related Articles</h2>
<div id=“related_articles”>
<txp:related_articles limit=“5” break=“li” wraptag=“ul”/>
</div>

however when there is no related article to display you still see the <h2>Related Articles</h2> on the page

is there a way to only display this section of code if there are related articles?

Offline

#2 2007-05-22 16:32:47

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: Display section of code only when there is a related article

Remove the <h2> part from the template and add it in the article form:

<txp:if_different><h2>Related Articles</h2></txp:if_different>

Because of the if_different tag, it is only displayed the first time.

Last edited by ruud (2007-05-22 16:33:04)

Offline

#3 2007-05-22 16:50:22

beechy
Member
Registered: 2006-03-02
Posts: 92

Re: Display section of code only when there is a related article

Thanks for that ruud…

but I dont have the related article tag in my main article page its in a side bar as a menu list so i cant put it in the article form. Any other suggestions.

Offline

#4 2007-05-22 16:57:17

Zanza
Plugin Author
Registered: 2005-08-18
Posts: 699
Website

Re: Display section of code only when there is a related article

Label and labeltag attributes looks like the right way.

Z-

Offline

#5 2007-05-22 17:07:43

beechy
Member
Registered: 2006-03-02
Posts: 92

Re: Display section of code only when there is a related article

thanks for that Zanza I used…

<txp:related_articles limit=“5” break=“li” wraptag=“ul” label=“Related Articles” labeltag=“h2” />

which works perfect!

Last edited by beechy (2007-05-22 17:08:12)

Offline

#6 2007-05-22 17:30:22

beechy
Member
Registered: 2006-03-02
Posts: 92

Re: Display section of code only when there is a related article

Just in case anyone else comes across this problem as well

In FF the empty divs were fine however in IE6 empty divs had a mind of their own and seemed to have a default height for some reason.

I found that if i put a comment box inside the empty div .i.e

<div id=“related_articles”>
<!— ***** IMPORTANT MAKES DIV HIDE IN IE WHEN EMPTY ***** —>
<txp:related_articles limit=“5” break=“li” wraptag=“ul” label=“Related Articles” labeltag=“h2” />
</div>

Then the div would hide correctly in IE6

Last edited by beechy (2007-05-22 17:31:10)

Offline

#7 2007-05-22 21:13:01

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Display section of code only when there is a related article

You could do this with chh_if_data

<txp:chh_if_data>
<div id="related_articles">
<txp:related_articles limit="5" break="li" wraptag="ul" label="Related Articles" labeltag="h2"  />
</div>
</txp:chh_if_data>

to avoid empty divs.

Offline

Board footer

Powered by FluxBB