News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Remove Group Name And Replace With Graphic

Started by Vyazhan, May 01, 2016, 11:17:04 AM

Previous topic - Next topic

Vyazhan

Hey guys,

I have been searching the forums a bit already but couldn't find a satisfactory answer, so I hope someone here can help me out :)

I am trying to assign a graphic to a group (Administrators) so instead of displaying "Administrators" and the corresponding star images, I would like to have just the star image which I would replace with a badge and then disable the "Administrator" text completely, but only for some of my groups. I still want to be able to have the rest of the functionality untouched, so post-based groups still have both the name and the associated stars displayed.

Alternatively, if it would be possible to just replace the text of the group with a badge, that would be fine too :) Edit: Thinking about it more now, the alternative would probably be easier to realize and I would be very happy with this, if this is possible!

Thanks a lot for your help guys and very much looking forward hearing back from you!

All the best,
Vaya

Illori

you should not replace the group name with the badge. that can and will cause issues.

there really is not a good solution to the issue you have.

qc

A simple javascript might work for you:
<script>
var groups = document.querySelectorAll('.membergroup');
for (var i = groups.length; i-- > 0;) {
  if (groups[i].innerHTML == 'Administrator') {
    groups[i].innerHTML = '<img src="https://image.freepik.com/free-icon/security-badge_318-79029.png">';
  }
}
</script>


Alternatively, you can edit the display.template.php to perform this replacement in PHP - or modify the core to allow HTML as group names - or modify display.template.php to give each ".membergroup" element an additional class or data attribute containing e.g. the group id and then adding a CSS rule based on that id.
Playing quizduell? Having quizduell questions? Our german quizduell forum quizcommunity.de is looking for quiz freaks to come and play quizduell with us :)

Kindred

Wait... You don't need any coding at all...

Replace star image with the badge and only display one...   Like we do here
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

qc

Quote from: Kindred on May 01, 2016, 06:03:50 PM
Wait... You don't need any coding at all...

Replace star image with the badge and only display one...   Like we do here
You would still need to get rid of the membergroup name "Administrator" then, wouldn't you?
Apart from that, seems like the simplest solution.
Playing quizduell? Having quizduell questions? Our german quizduell forum quizcommunity.de is looking for quiz freaks to come and play quizduell with us :)

Vyazhan

Quote from: qc on May 01, 2016, 06:33:44 PM
Quote from: Kindred on May 01, 2016, 06:03:50 PM
Wait... You don't need any coding at all...

Replace star image with the badge and only display one...   Like we do here
You would still need to get rid of the membergroup name "Administrator" then, wouldn't you?
Apart from that, seems like the simplest solution.

Yes, thanks a lot for the input, I did see the trick with the single badge and I might use that for some ranking related stuff, but I think the Javascript sounded promising, or at least the approach to this :)

However, I am still a PHP noobie and beginner and tried for a while now to slot that above code in somewhere, to no success. So if you could enlighten me as to where exactly to place this and how exactly the code would look, I am sure I would get it then :)

Thanks a lot for all the timely help, it's much appreciated!

Advertisement: