MyBB Community Forums

Full Version: PHP in Templates and Template Conditionals
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
i use below code
<if (in_array($mybb->user['usergroup'], array(4,8,9)) && in_array($forum['fid'], array(168))) then>

<span class="smalltext">
<a href="{$lastpost_link}" title="{$full_lastpost_subject}"><strong>{$lastpost_subject}</strong></a>
<br />{$lastpost_date}<br />{$lang->by} {$lastpost_profilelink}</span>

<else> Protected Forum
</if>

But it show 'Protected Forum' under all forum last post rather than in forum id 168.
Is there any issue with code?
Probably because "Protected Forum" is in the <else> part? If you want it the other way round, just place it the other way round.
How to play bro?
It giving to all members same text.
i dont know?
pls guide.

i want to show last post on forum n forum 168 to only usergroup 4,8,9.
and other usergroup to show Protected forum.

Please help me guys, if you want give me solution in PM.
Please.

Any helping guy please?
(2016-01-30, 08:30 AM)Dr_The_One Wrote: [ -> ]i use below code
<if (in_array($mybb->user['usergroup'], array(4,8,9)) && in_array($forum['fid'], array(168))) then>

<span class="smalltext">
<a href="{$lastpost_link}" title="{$full_lastpost_subject}"><strong>{$lastpost_subject}</strong></a>
<br />{$lastpost_date}<br />{$lang->by} {$lastpost_profilelink}</span>

<else> Protected Forum
</if>

But it show 'Protected Forum' under all forum last post rather than in  forum id 168.
Is there any issue with code?

Look at your if statement. If the user is in group 4, 8, or 9 and is viewing forum 168 then display the last post information; else (meaning user is not in group 4, 8, or 9 or the forum isn't 168), then display Protected Forum.

<if (in_array($mybb->user['usergroup'], array(4,8,9)) || ! in_array($forum['fid'], array(168))) then>

<span class="smalltext">
<a href="{$lastpost_link}" title="{$full_lastpost_subject}"><strong>{$lastpost_subject}</strong></a>
<br />{$lastpost_date}<br />{$lang->by} {$lastpost_profilelink}</span>

<else> Protected Forum
</if>

My modified code shows the last post information if the user is in a privileged group OR the user is viewing a non-protected forum.
Help please! I tried <?php echo "Hello World"; ?> it's not working?
^ which plugin you have used ? there are two variants - one for using php codes and the other is for the conditionals
(2016-09-13, 02:57 AM).m. Wrote: [ -> ]^ which plugin you have used ? there are two variants - one for using php codes and the other is for the conditionals

The first one that allows everything. I tried putting it in my main and inc folders and nothing worked :/
<if ($mybb->user['pms_unread'] >0) then>
<style type="text/css">
.pm_alert 
{
 background: #fff;
}
</style>
<else>
<style type="text/css">
.pm_alert
{
 background: rgba(12,146,0,0.5);
}
</style>
</if>



I have this code but it doesnt work on Mybb 1.8.
I did download the PHP plugin and activate it from ACP.
Im guessing problems are these ">" at "->user" and ">0) then"
I have the same problem as  DjPrison above.

This code works fine in 1.6.* for everybody but in 1.8.9 it doesn't:
<if !empty($user['fid5']) then><div class="Profilfelder" width="170px"><b>ALTER</b></div>
<?php echo $parser->parse_message(htmlspecialchars_decode($user['fid5']),array('allow_mycode'=>1));
?></if>
 
Usually this error is screened but:
Quote:Fatal error: Call to a member function parse_message() on a non-object in .../memberlist.php(428) : eval()'d code(7) : eval()'d code on line 1

I also think that it might be connected to the "->" bit because the if-part alone works and I can also use random words to echo However I can't think of a workaround for the parse-bit I need the mycode to be parsed...

Any ideas?  Huh


Side note/fun fact:
I have found two random accounts where the code works and no error is displayed (meaning i log into the account an can view the memberlist with no problem). Those two accounts are in no way different from the others where it doesn't work (same usergroup, same rights, same entries in the profilefields...) so i'm running out of ideas there, too.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22