PDA

View Full Version : if post count conditional


hilaryl
03-25-2015, 12:44 AM
Hi everyone,

Fairly sure this is a simple request, but can't quite figure out how to do it.

I want to include a conditional statement in a users postbit if the user has made more then X posts. I know I can get the total number of posts from the user using this {vb:raw post.posts}

That returns a number like 1,784

How can use that variable in a conditional though?

Essentially 'if {vb:raw post.posts} > 1000' Do this.....

Can anyone help out? What's the correct syntax?

Cheers,
hilaryl

Elite_360_
03-25-2015, 01:53 AM
<vb:if condition="$post['posts'] > 1000">
Code Here
</vb:if>

hilaryl
03-25-2015, 04:00 AM
Thanks for the code.

Unfortunately this isn't working though, and I'm fairly sure it's because '$post['posts']' is equal to a number with a comma in it. As in it's equal to '1,060'.

How can I turn '1,060' into '1060' so I can compare the numbers?

Elite_360_
03-25-2015, 07:21 PM
Make a new plugin

Product = vBulletin

Hook Location = postbit_display_complete

Title = what ever you want for a tiltle

Execution Order = 5

Plugin PHP Code



$post['new_user_posts'] = str_replace(',', '', $post['posts']);




Plugin is Active = check to Yes


New Condition



<vb:if condition="$post['new_user_posts'] > 1000">
Code Here
</vb:if>

hilaryl
03-25-2015, 10:28 PM
Fantastic - thanks for being so thorough with your explanation.

I'll give it a go shortly and let you know how I go.

Thanks,
hilaryl

--------------- Added 1427333234 at 1427333234 ---------------

Works like a charm!

Actually ended up tweaking it a bit and added what I wanted into another template_hook so I don't have to alter the post_bit template.

Full plugin code below:


$new_user_posts = str_replace(',', '', $post['posts']);

if ($new_user_posts > 500) {
$template_hook['postbit_userinfo_right_after_posts'] .= '<!--<dt></dt><dd>' . $new_user_posts . '</dd>-->';
}