问题
i would like to ask if there is an elseif statement in blogger? All i've seen is only if and else but no elseif.
If there isn't any elseif statement, how can i give multiple condition to an if statement?
For instance in this case, i have 3 author A B and C. Recently D and E have joined us, i have a code such that if the author is A B or C, it will post their respective images
<b:if cond='data:post.author == "Author-A"'>
<img class='ava' height='100'
src='img-URL-1'
width='100'/>
</b:if>
<b:if cond='data:post.author == "Author-B"'>
<img class='ava' height='100'
src='img-URL-2'
width='100'/>
</b:if>
and so on. But if the author is not A B or C, the CSS would screw up my blog post, so i thought of using elseif for this and if elseif is not available in this case, i thought of adding this after the above code
<b:if cond='data:post.author != "Author-A" && "Author-B" && "Author-C"'>
<img class='ava' height='100'
src='else-IMG-URL'
width='100'/>
</b:if>
But i've tried that and it doesn't seem to work it says && is invalid. Any idea what i should put in to use as OR ?
回答1:
Translated in pseudocode you logically rather want to do the following:
if (author != A && author != B && author != C)
and thus not what you tried:
if (author != A && B && C)
回答2:
<b:if cond='condition1'>
Do something for 1
<b:else/>
<b:if cond='condition2'>
Do something for 2
<b:else/>
<b:if cond='condition3'>
Do something for 3
<b:else/>
Do something for others
</b:if>
</b:if>
</b:if>
回答3:
if you want to do a logical end-ing then use this format:
<b:if cond='condition 1'>
<b:if cond='condition 2'>
contents go here
</b:if>
</b:if>
回答4:
Perhaps you need to specify &&
as &&
?
That should resolve the error message you're getting. You will likely still have to fix the logic problem that BalusC pointed out.
来源:https://stackoverflow.com/questions/2032211/blogger-bif-statement