specstanza (@specstanza)

Forum Replies Created

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

  • specstanza
    Participant

    @specstanza

    Hi @markusb,
    If I understand your issue well, I think this other topic could help you.


    specstanza
    Participant

    @specstanza

    Hi!

    To anyone in need of a login menu item with both user avatar and Link to the Bbpress dashboard in 2022, here’s my version of @robkk ‘s code :

    add_filter('wp_nav_menu_items','rk_bbp_menu_profile_link', 10, 2);
    function rk_bbp_menu_profile_link( $items, $args ) {
        if( is_user_logged_in() && $args->theme_location == 'menu-1')  {
    	$current_user = wp_get_current_user();   
    	    $user = $current_user->user_login ;
        $avatar = get_avatar( $current_user->ID, 64 );
    	$items .= '<li  class="NavBarLogin"><a href="/forums/users/' . $user . '/edit">' . $avatar .  'Mon compte</a></li>';
    }
    return $items;
    }

    specstanza
    Participant

    @specstanza

    A little update on this too. ๐Ÿ™‚

    The $count of favoriters is updated correctly on topic’s single page.
    But when the $count is called elsewhere, WordPress seems to take the first _bbp_favorite encounter.

    Looking at posts’ metavalues, it seems that every ‘favorite’ mention becomes an extra _bbp_favorite

    bbp_favorite

    My code doesn’t say anything about taking the highest number – maybe this would be the solution?

    $subscriptions = get_post_meta(get_the_ID(), '_bbp_favorite', true) ;
    $count = count($subscriptions) ;
    $output .= '<li><a href="' . get_permalink() . '">' . get_post_meta(get_the_ID(), 'an_extra_field', true) . '</a><br> <span> Votes :'  . get_post_meta(get_the_ID(), '_bbp_favorite', true) . '</span></li>';
              }
              $output .= '</ul>';
              wp_reset_query();
         }
         return $output;
    }

    specstanza
    Participant

    @specstanza

    Thank you @robin-w !
    My first idea was to display:none the_title but I’m definitely going to keep it.

    I found the solution by installing a plugin called Hookr. It gave me some informations I needed after hours reading Bbpress’ files.

    The ouput is a bit strange though…
    Output true_title

    As if the voice-count moved somewhere. The author is also displayed twice – I don’t remember it was like that before. Changing the shortcode used doesn’t improve this.

    I’m going to figure out what happened here and keep this thread updated if it’s usefull for someone. ๐Ÿ™‚


    specstanza
    Participant

    @specstanza

    To anyone who would come accross the same project, I added an action to the bbp_theme_before_topic_title hook.

    For now, it does not displays as I would like but some CSS will do the trick.

    add_action('bbp_theme_before_topic_title', 'show_true_title');
    function show_true_title() { 
    $topic_id = bbp_get_topic_id();
      $true_title = '<li><a href="' . get_permalink() . '">' . get_post_meta( $topic_id, 'bbp_extra_field1', true); '</a>';
    echo $true_title ;

    specstanza
    Participant

    @specstanza

    Thank you so much @robin-w – changed the subscription to fav with bbp_get_topic_favoriters ๐Ÿ™‚

    add_action('bbp_template_before_single_topic', 'show_bbp_sub');
    function show_bbp_sub() { 
    	$subscriptions = bbp_get_topic_favoriters(bbp_get_topic_id()) ;
    	$count = count($subscriptions) ;
    	echo 'number of users subscribed: '.$count;
    }

    Now I only have to look for a way to display my topics and sorted them by numbers of favs! Thanks to you I know there was some major changes with the 2.6 version.


    specstanza
    Participant

    @specstanza

    Hi @robin-w – thanks for your answer.
    Here it is – as I’m still learning PHP, I apologize if I did a terrible coding mistake.
    I tried some modifications here and there (return, echoing other stuff) but nothing did the trick.

    /* tried to hook the code in my template */
    add_action('bbp_template_before_single_topic', 'show_bbp_sub');
    function show_bbp_sub() { 
    /* end of it */ 
     /* Original lines from @babblebey */
    $topic = bbp_get_topic_id();
    $users = get_users() ;
    $countsub = 0; /* I guess it's echoing only this line */
    foreach ($users as $user) {
        $topicsub_listarray = get_usermeta ($user->id, 'wp__bbp_subscriptions', true) ;
        $topicsub_list = explode (',' , $topicsub_listarray) ;
        if (in_array ($topic , $topicsub_list))  $countsub++ ;
    }
    echo $countsub;
    }
    

    Thank you for your help and your patience.


    specstanza
    Participant

    @specstanza

    Hi @babblebey & @robin-w , thank you both for your work on this matter.

    I’m trying to do the same on my Bbpress install (not online yet) in order to sort topic by number of “fav mentions”.

    I tried your last two codes but it returns “0” (I hooked them on bbp_template_before_single_topic and putted them in two separated functions).

    Does it still works for you? Did I get it all wrong?

    Thank you for your answer. ๐Ÿ™‚


    specstanza
    Participant

    @specstanza

    4 years after your reply, I had to loggin to thank you properly @elhardoum.
    Works amazingly for my CPT. Thank you so much!

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