Does anyone know how I can set a variable in a weblog:entries loop and then use that variable in a conditional {if} statement?
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
April 24, 2008 10:08am
Subscribe [2]#1 / Apr 24, 2008 10:08am
Does anyone know how I can set a variable in a weblog:entries loop and then use that variable in a conditional {if} statement?
#2 / Apr 24, 2008 10:31am
What would you want to achieve by that? There might be a preset variable for you. Failing that, PHP can certainly do that.
#3 / Apr 24, 2008 3:54pm
I have a weblog entries loop where I select 2 different statuses, open and feature. I was to suppress the first occurance of the feature status since the first featured article will be on the page in a prime location.
the offset doesn’t seem to be powerful enough to offset against a specific status when working with multiple statuses. So, what i am trying to do is figure out how to test for {status} being ‘feature’ and then not display the first occurance of that but display all others with that status.
So, I thought if I could set a variable so I know I suppressed the first featured item from displaying. Then on each loop, I could then use that variable as a test.
I am open to better ideas, and if I have to use PHP, an example would be very helpful.
thanks!!!!!
M-
#4 / Apr 24, 2008 6:18pm
In your case, I think, it will have to be PHP. Basically, you would do the following:
Every time you’d encounter status=“feature” you’d check a counter. If it is 1, you skip that posting, in all other cases you simply increment that counter by 1. Other statuses don’t trigger the code. Am I making sense?
#5 / Apr 24, 2008 6:37pm
Thanks!!!
I’ve been working on this code, and playing the php buttons. Here is the logic that I am using. Thanks for the inspiration! So this will drop the first ‘front_feature’ since that gets a prime spot elsewhere on the page. All other front_features are displayed becuase the $skip variable get set after the first one…
<?php
if ("{status}" == "front_feature" AND !isset ($skip)) {
$skip = "1";
} else { ?>
<!-- start entry -->
bla bla bla
<!-- end entry -->
<?php } ?>#6 / Apr 24, 2008 6:41pm
Looks good, at a glance. Have you given it a try? Let us know how it goes.
#7 / Apr 24, 2008 10:10pm
yes! I just finished it up and it is just loverly.
you can see it at: http://www.boomercoffeehouse.com/index.php/self_expression/category/C11/
Thanks again!
M-
#8 / Apr 25, 2008 3:02am
Great it’s working for you 😊