MyBB Community Forums

Full Version: Postbit/Profile PHP template help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone! I was just looking for some help in getting my php template straight for my postbit and profile areas.

I've already installed the PHP in template plugin and verified that it's working. I'm trying to use it specifically to display custom profile fields who's contents will be HTML, as well as NOT display a field/the title of the field if it does not have any content.

For example;
if FID2 is filled out with a link to a website, I would want it to display

Website: User inputted link and title

if I had inputted the code...
<a href="http://www.mylinkhere.com" target="_blank">My Link Title</a>

As it stands presently, it's showing
 &lt;a href=http://www.google.com&gt;Test?&lt;/a&gt;

Additionally, I'm trying to have the field NOT show up if there's no input into the field. So it would go from

Website: User inputted link and title
to
(Nothing at all here)

Currently, this is what my PHP looks like in my postbit (classic):

<if $post['fid2'] then>{$post['fid2']}<br /></if>

I believe that when I get this over to my member's profile area, that it should go to $userfields['fidX'], but I'm not there as of yet. Any help on this would be appreciated!
I would advise against allowing user to input HTML in your custom fields. You may find this support/discussion thread useful re postbit.

http://community.mybb.com/thread-130300-...#pid956608

This is the code I use on my own profile page set up to parse user entered website field into something normal

<if $memprofile['website'] then>
		 <span><a href="<?=htmlspecialchars_uni($memprofile['website'])?>" target="_blank">website</a></span>
		 </if>

THIS CODE REQUIRES THE PHP IN TEMPLATES PLUGIN
Thank you for your quick reply!

I've got the PHP in Templates plugin installed and I reviewed that thread extensively Big Grin I'm fairly new to PHP, so while I was looking at it and trying to understand some of the theory behind it, I can't say I was being especially successful.

I'm fairly new to myBB (JUST installed it a week and change ago after farting around with IPB 3.2 for over 2 months), and I'm finding that I can do a lot more with myBB and with less work, it's just requiring a little brain stretching to grasp everything.

Is there a plugin that I would need to install in order for the PHP code in the other link to work, or is the PHP template both above/in the other thread sufficent to get it to work?
The discussion in the other post was about allowing BBcode in profile fields. There is a plugin for it on the Mods site.

The code in the link above would definitely get the website link to "work", but you can use the if else syntax in lots of cases. You just need to know what you are asking.

An example: This will display only for certain usergroups. handy for header notifications etc.
<if in_array($GLOBALS['mybb']->user['usergroup'], array(4,5,6)) then> stuff for usergroup 4,5,6</if>
Alright, I ended up using two Custom profile fields to do what I wanted (one for the web url, the second for the linkable verbiage).

I did have a question regarding that latest piece of PHP you just gave me - I'm trying to have certain portions on the postbit and member profile viewable only if the member who has posted/owner of the profile is of a certain group (I would like to hide the member's post count if they are a part of a group for out of character accounts, and have it shown for In Character).

If I understand correctly, the bit that I would have to change to try to get that effect would be the user['usergroup'], but I'm not totally certain what would need to be changed. Any hints?

Thank you for your help, I really appreciate it!
Are you referring to additional usergroups? Or is this a case of two profiles?

This might help, I use this code to hide the private messaging/email link on my profiles if the viewer is a guest, or if the profile viewer is the profile owner (I don't want them sending pms/emails to themselves)
<if $mybb->user['uid'] !=0 && $mybb->user['uid'] !=($memprofile['uid']) then>
<a href="private.php?action=send&amp;uid={$memprofile['uid']}" class="icon-mail"></a>
{$sendemail}</if>

Now, in theory you could change the uids here to usergroups

<if $mybb->user['usergroup'] =3 && $memprofile['usergroup'] =3 then>
some stuff you want to hide here
</if>

If these are additional usergroups then it gets a bit more complicated.
Predictably, they're additional user groups, LOL!

I tried
<if $mybb->user['usergroup'] =8 && $memprofile['usergroup'] =8 then>

some stuff you want to hide here

</if>

and the information still appears in both the postbit as well as the member's profile, regardless of whether I'm logged into an admin account or an account under the group id 8.

Just to clarify, I'm trying to restrict the viewable information based upon what group ID the poster is in, not necessarily the viewer. So, regardless of whether someone in my supermod group is viewing the post, or a guest, if the poser is in this group, I don't want their post count etc., to be displayed. I hope I'm being specific enough, I'm new to this and really appreciate you trying to decode my requests!