myBB - if statements

Ash

Madly Diligent
Joined
Nov 14, 2012
Messages
6,011
Reaction score
984
FP$
100
Forum Software - myBB

I am currently using this - {$newposts} to display the amount of posts made today on my forum
Is it possible to have an if statement so I can do something like this -

if {$newposts} = 10 then "display this message"
else
"display this message2"
 
Depending on where you are putting the code, if it is in a php file (and not a template file), you should be able to use something like this:

Code:
$count = $lang->new_posts;
if ($count =='10'){
echo "First Message";
}else{
echo "Second Message";
}

if $newposts is giving you your new post count, then maybe this instead:

Code:
if ($newposts =='10'){
echo "First Message";
}else{
echo "Second Message";
}
 
Skyon Archer said:
Depending on where you are putting the code, if it is in a php file (and not a template file), you should be able to use something like this:

Code:
$count = $lang->new_posts;
if ($count =='10'){
echo "First Message";
}else{
echo "Second Message";
}

if $newposts is giving you your new post count, then maybe this instead:

Code:
if ($newposts =='10'){
echo "First Message";
}else{
echo "Second Message";
}

When you use his code, you better replace == with >= if you want members with a higher postcount see the first message.
 
From what I can tell, this doesn't exist in Vanilla MyBB, although there are apparently plugins that let you embed PHP code or use custom conditionals. I recommend searching around for a good plugin to do this.

Otherwise, you can always do it via JavaScript. This requires jQuery. Here's some example code, although I haven't tested it.

Code:
<script type="text/javascript">
$(document).ready(function() {
var posts = parseInt($("#newposts"));
if (posts > 10) {
alert("Some text");
}
});
</script>
<div id='newposts' data-number='{$newposts}'></div>
 
Back
Top Bottom