View Full Version : Picking Alternate Posts With A Conditional
madshark
02-23-2011, 07:56 AM
I'm trying to pick out ever alternating post with a conditional. I recall successfully doing this with
<vb:if condition="$post['postcount'] % 2 == 0">
on 4.0.3 or the likes.
However with 4.1.2 it doesn't seem to work. Or I just cant remember the correct coding. Could anyone please shed some light?
A typical usage would be to have alternating postbit colours.
Thank You.
Lynne
02-23-2011, 05:05 PM
What template are you putting this in? And can we see exactly what you are adding and where?
madshark
02-23-2011, 05:30 PM
I basically want the postbit userinfo to alternate. Left and Right. Ive done it before. I just haven't used VB for awhile and cant remeber how the heck I did it for the life of me as my forum was pretty much closed down.
What I do know is that I used it in the postbitlegacy template.
And basically I used a second CSS for userinfo (i.e userinfo1) with a float right.
.postbitlegacy .userinfo1 {
float:{vb:stylevar right};
position: relative;
width:{vb:math {vb:stylevar postbitlegacy_userinfo_width}-{vb:math {vb:stylevar padding}*2}};
padding: 2px {vb:stylevar padding} {vb:math {vb:stylevar padding}/2};
font-size: {vb:stylevar small_fontSize};
display:block;
background: {vb:stylevar postbit_userinfo_background};
clear:both;
}
So in theory and again if memory serves me well the code should look something like this I take it...
<div class="postdetails">
<vb:if condition="$post['postcount'] % 2 == 0"><div class="userinfo"><vb:else /><div class="userinfo"></vb:if>
<div class="username_container">
<vb:if condition="$post['userid']">
{vb:raw memberaction_dropdown}
{vb:raw post.onlinestatus}
<vb:else />
<span class="username guest">{vb:raw post.musername}</span>
</vb:if>
</div>
Im fairly certain I used something very similar to the above. For some reason it seems to break the whole post bit this time around. However if i just switch the userinfo to userinfo1 minus the conditional the post bit displays the userinfo on the right with no issue. So the css seems to be problem free.
Any ideas?
Thanks.
Lynne
02-23-2011, 05:35 PM
You do see that you have the same class in both the if and else?
<div class="userinfo"><vb:else /><div class="userinfo">
It works fine on my forum if I change that line to have different classes.
madshark
02-23-2011, 06:19 PM
My bad I typed that out half asleep. whee hours of the morning here lol. Pretty sure I used different classes when I tried it.
Odd. I shall check it again in the a.m and post back. But basically you implemented exactly what I posted above yes ?
Lynne
02-23-2011, 08:25 PM
I implemented the class change in my postbit_legacy and it worked. I did not check your CSS, but the class is definitely changing in alternate posts.
madshark
02-26-2011, 05:41 AM
The CSS needed to be changed in more than one place. Postdetails needed to be aligned as well. And another conditional needed to be added. Not too shabby.
Thanks Lynne
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.