Skip to:
Content
Pages
Categories
Search
Top
Bottom

Username list for each voice

  • Hi,

    I’m working on a new theme and I want to display a username list for each voice in ‘topic.php’.

    HTML example:

    <ul>
    <li>username voice 1</li>
    <li>username voice 2</li>
    <li>username voice 3</li>
    ...
    </ul>

    Is it possible to achieve without plugin?

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

  • Sam Bauers
    Participant

    @sambauers

    The voice information that is stored is just a count that is kept up to date in the topic meta. What you want has no easy built in solution.

    Thanks for your reply!

    And if I want to create a list of each users who marked the topic as a favorite, this is the same problem ?


    _ck_
    Participant

    @_ck_

    Same problem because favorites are stored serialized in user meta.

    Both of these issues can be addressed via a plugin however.


    _ck_
    Participant

    @_ck_

    If you add this code into a file called functions.php and put it into your theme folder, it will show the active names in the topic (if there is more than one person) It uses one extra query but it will also will work on 0.9

    add_action('topicmeta','voices_named');
    function voices_named() {
    global $bbdb, $topic;
    $names=$bbdb->get_col("SELECT DISTINCT user_login FROM $bbdb->posts LEFT JOIN $bbdb->users ON poster_id=ID WHERE topic_id=$topic->topic_id AND post_status=0");
    $count=count($names);
    if ($count>1) {echo "<li>$count members active on this topic: ".implode(", ",$names)."</li>";}
    }

    Thank’s _CK_ !!

    But, your code doesn’t seem to work in bbPress 1.0 (I tried to add it in functions.php or directly in topic.php).

    However I have no problem if I add your code in bbPress 9.0 theme.

    I want to add ” <?php echo bb_get_avatar( $poster_id->ID, $size , $default); ?> ” in your code, but I can not ?


    _ck_
    Participant

    @_ck_

    I actually had it tested in 1.0, if it’s not working in your theme and it’s a custom theme, make sure you have a do_action('topicmeta') somewhere in there.

    Adding avatars makes it much more complicated, I’ll give a shot at the code in a minute.


    _ck_
    Participant

    @_ck_

    This will show avatars

    add_action('topicmeta','voices_named');
    function voices_named() {
    global $bbdb, $topic;
    $results=$bbdb->get_results("SELECT ID,user_login FROM $bbdb->posts LEFT JOIN $bbdb->users ON poster_id=ID WHERE topic_id=$topic->topic_id AND post_status=0 GROUP BY poster_id");
    $count=count($results);
    if ($count>1) {
    foreach ($results as $result) {$ids[$result->ID]=$result->ID;}
    bb_cache_users($ids);
    $list="";
    foreach ($results as $result) {$list.=bb_get_avatar($result->ID, 16).$result->user_login.", ";}
    $list=trim($list,", ");
    echo "<li>$count members active on this topic: $list</li>";
    }
    }

    Thanks a lot _CK_ !!!

    It works with “Kakumei”, I need to re-check my custom Template, because nothing seems to appear.

    Hi,

    I want to add a link to the profile page:

    foreach ($results as $result){$list.=" <li class='list_b'>".bb_get_avatar($result->ID, 25, $default)."<a href='" .$result->user_profile_link. "'>".$result->user_login."</a></li> ";}

    I tried .$result->user_profile_link., but it doesn’t work, any idea ?


    _ck_
    Participant

    @_ck_

    I really can’t build an entire custom plugin for you.

    What you are trying to do will require API functions because the profile link doesn’t exist until it’s calculated. You’ll have to use the get_profile_link functions and send it the user id.

    bb_get_profile_link($result->ID)

    Curiously if I write the code in “functions.php” that break my login/logout/edit profile page and display a blank page. I have moved the code in “my-plugins” and no issue now.

    Thank you for your information and your patience _ck_, I will try to solve my last problem by my self.

    Edit: solved with :

    foreach ($results as $result){$list.=" ".bb_get_avatar($result->ID, 20, $default)."<a href='".bb_get_option('uri')."profile/".$result->user_login."'>".$result->user_login." </a>";}

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

You must be logged in to reply to this topic.