MyBB Community Forums

Full Version: display a username in header
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
hi
how do i retrieve the username and post count and show it in the header

kenny
Use this variable for username:
{$mybb->user['username']}

For post counts of the user:
{$mybb->user['postnum']}
sorry should have said a specific user
Which user? How do you plan to choose such user?
i know the user i want to display and it will not change i also want to show the users last visit and post count

example

bob 17/10/2012 39 posts
Something like this?

<?php
define("IN_MYBB", 1);
require ('global.php'); // be sure that u r running this php-code in the same
// directory of global.php, or else change the path.
$user = get_user(SPECIFIC_UID);
$name = $user['username'];
// grab other info in same pattern
?>
<?echo $name?>
You probably can use something like Template Conditionals. header template:
<setvar user>get_user('USERID')</setvar>
<if $tplvars['user']['uid'] then>
Username: <func htmlspecialchars_uni>$tplvars['user']['username']</func>
Post Count: <?=my_number_format($tplvars['user'][''postnum''])?>
</if>

But, if the desired information is not supposed to be frequently changed, then probably using some kind of cache method, or even static information could be better when it comes to performance.
I guess you will have to get the data from the database...
You probably will need a plugin, since, AFAIK, we can't use PHP in templates
It will be a simple plugin though, just to grab the data from the database and display it in the header.