Skip to:
Content
Pages
Categories
Search
Top
Bottom

Topic background color depending on role


  • arno8
    Participant

    @arno8

    Is it possible to give the topic background a specific color depending on authors rank?

    I would like it so from keymasters it adds a yellow background to the topic.

    Thanks in advance

Viewing 13 replies - 1 through 13 (of 13 total)

  • Robkk
    Moderator

    @robkk

    well you can check out this topic and maybe it will help

    How to change Admin Reply

    when schmoos code has .user-id-1 well thats the id of the user

    go to user>all users search for all your sites keymasters.

    then click edit by each users avatar

    after that you are in the edit profile page for that particular user and in the url it says user_id=(number)

    get all the user id numbers and then you can stack them using commas in a css code like this

    .type-reply.user-id-1,.type-reply.user-id-2,.type-reply.user-id-3 { background: yellow; }


    arno8
    Participant

    @arno8

    Thanks this did it man , could you help me with this to:

    im trying to add small images in front of the roles, every role has a different one, so im trying to add a class depending on the role, i know i gotta make edits in loop-single-reply.php

    right here somewhere

    
    	<div class="bbp-reply-author">
    
    		<?php do_action( 'bbp_theme_before_reply_author_details' ); ?>
    
    		<?php bbp_reply_author_link( array( 'sep' => '<br />', 'show_role' => true ) ); ?>
    
    		<?php if ( bbp_is_user_keymaster() ) : ?>
    
    			<?php do_action( 'bbp_theme_before_reply_author_admin_details' ); ?>

    You got any ideas?


    Robkk
    Moderator

    @robkk

    well first i think you have to seperate the role from the author link and author avatar

    then to do add this you have to either add conditionals like if user is admin {

    or wrap the role in a class and add something like ($role)

    will post later when i feel like going into templates and fiddling with them again.


    arno8
    Participant

    @arno8

    Thanks man, I can’t wait to see this properly 😀 hopefully soon.

    btw the site I wanna add it to is http://www.primeknights.com, so u can get an idea of what I’m trying to do.

    This should do the trick without any template modifications:

    
    add_filter('bbp_before_get_reply_author_role_parse_args', 'ntwb_bbpress_reply_css_role' );
    function ntwb_bbpress_reply_css_role() {
    
    	$role = strtolower( bbp_get_user_display_role( bbp_get_reply_author_id( $reply_id ) ) );
    	$args['class']  = 'bbp-author-role bbp-author-role-' . $role;
    	$args['before'] = '';
    	$args['after']  = '';
    
    	return $args;
    }
    
    add_filter('bbp_before_get_topic_author_role_parse_args', 'ntwb_bbpress_topic_css_role' );
    function ntwb_bbpress_topic_css_role() {
    
    	$role = strtolower( bbp_get_user_display_role( bbp_get_topic_author_id( $topic_id ) ) );
    	$args['class']  = 'bbp-author-role bbp-author-role-' . $role;
    	$args['before'] = '';
    	$args['after']  = '';
    
    	return $args;
    }
    

    It grabs the topic or reply author role and adds another CSS class with prefix bbp-role- so you now have a new set of CSS classes e.g. bbp-role-keymaster, bbp-role-moderator, bbp-role-participant etc that you can then add your custom CSS styles to.


    arno8
    Participant

    @arno8

    And where would I add the add_filter code please?


    arno8
    Participant

    @arno8

    @robkk it only worked on 1 topic, how can i get it working for the enitre forum?


    Robkk
    Moderator

    @robkk

    you put the add filter code into your child themes functions.php or if you have a functionality plugin put it there.

    and well i havent really tested that css code before so i didnt know if it really did work.
    i just tried it a while ago and i cant get it to work at all.

    if you got it to work send a link to the post so i can check it out.


    arno8
    Participant

    @arno8

    you put the add filter code into your child themes functions.php or if you have a functionality plugin put it there.

    This worked perfectly.

    if you got it to work send a link to the post so i can check it out.

    i dont get it work 🙁


    Robkk
    Moderator

    @robkk

    @arno8 yeah i worked on this for awhile i cant get it to show a color based on the user id of the reply author on the topic background.

    just so you know it should be something like this for topics.

    .type-topic .user-id-1,
    .type-topic .user-id-2,
    .type-topic .user-id-3 { 
    background: yellow; }

    Robkk
    Moderator

    @robkk

    try this

    i think this should work now

    #bbpress-forums li.bbp-body .user-id-1,
    #bbpress-forums li.bbp-body .user-id-2 {
    background:yellow;
    }

    arno8
    Participant

    @arno8

    Sorry to come back late to this @robkk , I got this working with

    #bbpress-forums .type-reply.user-id-6 {
        background:url(https://www.primeknights.com/wp-content/uploads/2014/09/Naamloos-2.jpg) repeat;
    }
    #bbpress-forums div.odd.user-id-6 {
            background:url(https://www.primeknights.com/wp-content/uploads/2014/09/Naamloos-2.jpg) repeat;
    }

    Thnx for your help 🙂


    youishih
    Participant

    @youishih

    This is my first time to create a plugin by myself. I use this tutorial to create the plugin. Then, copy the code mentioned above, and it works perfectly. Thank you!

Viewing 13 replies - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.