How can I get a person's membergroup to be shown on all pages?

Started by Ertado, September 21, 2008, 08:23:21 PM

Previous topic - Next topic

Ertado

I would like to be able to display a person's membergroup in index.template.php so it shows up on every page on the forum. I've tried using:

$context['member']['post_group']

But that only works when I'm on the profile page. I figure something in the code of the profile page must be getting this information from the database so I would like to copy this into SSI.php or something of the sort so that I can use it everywhere.

Same goes for membergroup stars.

greyknight17

Shouldn't be a big problem. Open up your index.template.php:

Code (Search for) Select
echo '
<a href="', $scripturl, '?action=unread">', $txt['unread_since_visit'], '</a> <br />
<a href="', $scripturl, '?action=unreadreplies">', $txt['show_unread_replies'], '</a><br />';


Code (Replace with) Select
echo '
<b>Membergroup: ', $context['member']['group'], '</b><br />
<a href="', $scripturl, '?action=unread">', $txt['unread_since_visit'], '</a> <br />
<a href="', $scripturl, '?action=unreadreplies">', $txt['show_unread_replies'], '</a><br />';


That will display your non-post based membergroup (Administrator, Global Moderator, etc.). If you want it to display your post based membergroup, replace the following line:

Code (Search for) Select
<b>Membergroup: ', $context['member']['group'], '</b><br />

Code (Replace with) Select
<b>Membergroup: ', $context['member']['post_group'], '</b><br />

If you want the stars, replace it with:

<b>Membergroup: ', $context['member']['group_stars'], '</b><br />

Ertado

Yeah see that's what I mean, I've already done that but nothing will show up there unless I'm on a profile page.

greyknight17

It should work fine. Can you attach your Display.template.php file here? We'll see how that's picking up the membergroups.

Ertado

It's just an unedited 1.6 Display.Template.php file. It shows membergroups through this:

$message['member']['group'],
$message['member']['post_group'],

Ertado




Ertado

Do the people who actually wrote this code still come here? They might know.

[SiNaN]

Unfortunately it is loaded in at least 'normal' mode. So we need a edit to load it.

../Sources/Load.php

Find:

SELECT mem.*, IFNULL(a.ID_ATTACH, 0) AS ID_ATTACH, a.filename, a.attachmentType
FROM {$db_prefix}members AS mem
LEFT JOIN {$db_prefix}attachments AS a ON (a.ID_MEMBER = $ID_MEMBER)


Replace:

SELECT mem.*, IFNULL(a.ID_ATTACH, 0) AS ID_ATTACH, a.filename, a.attachmentType,
IFNULL(mg.groupName, '') AS member_group, IFNULL(pg.groupName, '') AS post_group
FROM {$db_prefix}members AS mem
LEFT JOIN {$db_prefix}attachments AS a ON (a.ID_MEMBER = $ID_MEMBER)
LEFT JOIN {$db_prefix}membergroups AS pg ON (pg.ID_GROUP = mem.ID_POST_GROUP)
LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.ID_GROUP = mem.ID_GROUP)


Then you can use $user_settings['member_group'] and $user_settings['post_group'] with globalling $user_settings in the function you use them.
Former SMF Core Developer | My Mods | SimplePortal

Ertado

Yes, thank you!

Quick question, if I want to create a query which executes on page load and the results of which can be displayed on every page, would I put it in Load.php?

[SiNaN]

Yes. You can either add your query to a function that has the same concept or create a new function and call it in index.php.
Former SMF Core Developer | My Mods | SimplePortal

Ertado

I'm having trouble getting member group stars to show on each page. I tried using the same method you used for the membergroup and postgroup names, but the group stars seem to be more complicated because the stored value is in the form of "5#Star.gif". Any idea how to get them to show up on all pages? (They only show when I'm on the profile page)

[SiNaN]

Add this after that query:

$user_settings['stars'] = empty($user_settings['stars']) ? array('', '') : explode('#', $user_settings['stars']);
$user_settings['group_stars'] = str_repeat('<img src="' . str_replace('$language', 'english', isset($user_settings['stars'][1]) ? $settings['images_url'] . '/' . $user_settings['stars'][1] : '') . '" alt="*" border="0" />', empty($user_settings['stars'][0]) || empty($user_settings['stars'][1]) ? 0 : $user_settings['stars'][0]);
Former SMF Core Developer | My Mods | SimplePortal

Advertisement: