MyBB Community Forums

Full Version: Hide custom Postbit when null
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I added a custom Postbit to my forums, the problem is it will always show, even if the user has left the entry blank.

[Image: postbits.png]


My code in postbit_author_user template looks like this.
{$lang->postbit_posts} {$post['postnum']}<br />
 {$lang->postbit_threads} {$post['threadnum']}<br />
{$lang->postbit_joined} {$post['userregdate']}
{$post['replink']}{$post['profilefield']}{$post['warninglevel']}<br />
 <a href="{$post['fid4']}"><img src="images/Rusted/steam.png"></a>

I'm pretty sure there needs to be some php executed somewhere that will hide this image from Postbits if it's blank.
Quote:if {$post['fid4']} == null
don't show image

The problem is, I'm not aware of the proper structure nor do I know where such php code should be executed from. I don't even know if this is the best method for doing what I want to achieve. I'm still learning and I'm not very experienced.

Any ideas? In advanced, thanks! Smile
First, install this mod. Yes, would work without it, but I like "costum php" in the templates directly and it's much easier. But that's not a must-do, I guess.

After installing, try to use this code on top of your template "postbit":
<?php

if(empty($post['fid4'])) {
$steam = "";
}
else { 
$steam = "<a href=\"{$post['fid4']}\"><img src=\"images/Rusted/steam.png\"></a>";
}

?>

After that, you could place 
{$steam}
 
wherever you want to in your template postbit. 

I'm not very good at this whole php-thingy but used this a lot of times, should work.  Smile  If you don't want to install php in templates, you can put the php into inc/functions_post.php D: Sorry if anything is wrong with my solution, as I said, I'm not very good. c: but I'm trying.
if you use template conditionals plugin (may download it here http://mybbhacks.zingaburga.com/showthread.php?tid=464) then you could do it right in template like this

<if !filter_var($post['fid4'], FILTER_VALIDATE_URL) === false then>
    <a href="{$post['fid4']}"><img src="images/Rusted/steam.png"></a>
</if>
Thank you both for the support, I ended up using avril's technique and it's working wonders thank you! Thanks for the plugin suggestion guys!