Problem with conditional
Posted: 16 May 2008 03:21 PM   [ Ignore ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  439
Joined  01-23-2006

Hi,

I’m trying to show a certain div class on the third weblog entry I"m displaying but it doesn’t seem to be working.  Any ideas?  Here is the template:

{exp:weblog:entries weblog="cases" limit="3" category="6"
disable="category_fields|member_data|pagination|trackbacks"}

<div class="common-col {if count == "3"}common-col-last{/if}">
<
h5>{title}</h5>
<
p><span class="date">{entry_date format="%F %d, %Y"}</span>
{exp:word_limit total="12"}{case-description}{/exp:word_limit}  
<a href="{url_title_path=work/cases}" class="link-readmore">Read More</a></p>

</
div>
{/exp:weblog:entries}

Thanks

Moderator’s note: Moved to Howto.

Profile
 
 
Posted: 16 May 2008 03:28 PM   [ Ignore ]   [ # 1 ]  
Research Assistant
RankRankRank
Total Posts:  385
Joined  02-14-2007

Your conditional seems a bit off.  Try this one:

<div {if count != 3} class="common-col" {if:else} class="common-col-last" {/if}>

Why is yours not working?  First, don’t use quotes around the number inside the if test--i.e. don’t do “3”.  It’s probably borking up the parser with all those double quotes.  Second, the way you wrote it, on the third pass through you are getting result like this :
<div class="common-col common-col-last"> which is probably not what you want. 

My version should work.  Hope this helps!

Profile
 
 
Posted: 16 May 2008 03:50 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  439
Joined  01-23-2006

Great.  Thanks

Profile
 
 
Posted: 16 May 2008 03:56 PM   [ Ignore ]   [ # 3 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  4897
Joined  04-15-2006

I think even easier would be to use the {switch} variable in this case wouldn’t it? As you are limiting the weblog tag to just three entries by hard-coding the limit="” parameter then you could use the switch variable to do what you need a little easier :

{exp:weblog:entries weblog="cases" limit="3" category="6" disable="category_fields|member_data|pagination|trackbacks"}

<div class="{switch="common-col|common-col|common-col-last"}">
<
h5>{title}</h5>
<
p><span class="date">{entry_date format="%F %d, %Y"}</span>
{exp:word_limit total="12"}{case-description}{/exp:word_limit}  
<a href="{url_title_path=work/cases}" class="link-readmore">Read More</a></p>
</
div>
{/exp:weblog:entries}

Untested but pretty sure that should work. Don’t know if that helps at all?

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!!
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 16 May 2008 04:18 PM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  439
Joined  01-23-2006

So that means that the first two entries will have the class common-col and the third will have common-col-last?

Thats’s cool.

Thanks Mark.

Profile
 
 
Posted: 16 May 2008 04:22 PM   [ Ignore ]   [ # 5 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  4897
Joined  04-15-2006

Pretty sure it should work, yes.

Perhaps give it a try and let me know? wink

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!!
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 16 May 2008 04:30 PM   [ Ignore ]   [ # 6 ]  
Research Assistant
RankRankRank
Total Posts:  385
Joined  02-14-2007

Yeah, I’d thought of that--using switch.  Thing is, every third entry will have that, (mitigated by using the limit of three, I know).  My way just did the third entry only, not every third entry. 

It’s an interesting design question, I suppose.  I wonder which is faster.

Profile
 
 
Posted: 16 May 2008 04:49 PM   [ Ignore ]   [ # 7 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  4897
Joined  04-15-2006

Well yes you are quite right and I did mention that this will only really work because the weblog tag has the limit="3” parameter on it. Not really sure which is faster though. Probably both the same I would imagine as we are still spitting out the three entries regardless.

Not too sure though so maybe an admin can let us know on that one but yes you are right that your way will work great too.

Another way is by doing this :

{exp:weblog:entries weblog="cases" limit="3" category="6" disable="category_fields|member_data|pagination|trackbacks"}

{if count
== "3"}
<div class="common-col-last">
{if:else}
<div class="common-col">
{/if}
<h5>{title}</h5>
<
p><span class="date">{entry_date format="%F %d, %Y"}</span>
{exp:word_limit total="12"}{case-description}{/exp:word_limit}  
<a href="{url_title_path=work/cases}" class="link-readmore">Read More</a></p>
</
div>
{/exp:weblog:entries}

Ever so slightly easier to read but that’s really down to the individual.

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!!
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
Posted: 17 May 2008 01:02 AM   [ Ignore ]   [ # 8 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  4897
Joined  04-15-2006

Actually I was a bit tired when I wrote that code above and it could probably be done even easier / better so that you don’t ever have to specify the number on which to place the last style.

Something like this instead :

{exp:weblog:entries weblog="cases" limit="3" category="6" disable="category_fields|member_data|pagination|trackbacks"}

{if count
== total_results}
<div class="common-col-last">
{if:else}
<div class="common-col">
{/if}
<h5>{title}</h5>
<
p><span class="date">{entry_date format="%F %d, %Y"}</span>
{exp:word_limit total="12"}{case-description}{/exp:word_limit}  
<a href="{url_title_path=work/cases}" class="link-readmore">Read More</a></p>
</
div>

{/exp:weblog:entries}

This has the added greatness that you can change the limit parameter to whatever value you like and the html code will update in conjunction with it.

Sorry! Should have thought a bit harder before posting that one but my excuse is that I was tired. Still tired now as we just had two cars crash outside our house at a very dangerous junction. Luckily no-one is hurt but two cars completely written off and Police sirens going off everywhere! Sleep pattern now definitely completely wrecked!

Best wishes,

Mark

 Signature 

Full List Of Plugins Here!!
 
Retrieve Statuses
Maximum Posts Reached
Neat Link
Redirect
Fetch URI

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 10:33 AM
Total Registered Members: 60720 Total Logged-in Users: 13
Total Topics: 73172 Total Anonymous Users: 7
Total Replies: 394653 Total Guests: 482
Total Posts: 467825    
Members ( View Memberlist )