• Resolved Redsand747

    (@redsand747)


    Hey Guys!

    First off, loving your plugin ?? Thanks for building it!!

    I’m trying to add the myCRED rank title below the commenters name in the list of comments that appears at the bottom of each blog post. I found the following support article, but I’m pretty sure the exact implementation will depend on the theme that you’r using – unfortunately after a few different tries I haven’t been able to get it:

    https://mycred.me/support/tutorials/adjust-comment-layout-according-to-rank/

    Here’s the code I’m trying to edit (I believe I’m in the right spot):

    <!-- display the comment -->
                <div class='comment_content'>
                    <header class="comment-header">
                        <?php
                        $author = '<cite class="comment_author_name"'.avia_markup_helper(array('context' => 'author_name','echo'=>false)).'>'.get_comment_author().'</cite>';
                        $link = get_comment_author_url();
                        if(!empty($link))
                            $author = '<a href="'.$link.'" '.avia_markup_helper(array('context' => 'comment_author_url','echo'=>false)).'>'.$author.'</a>';
    
                        printf(__('<cite class="author_name heading"'.avia_markup_helper(array('context' => 'comment_author','echo'=>false)).'>%s</cite> <span class="says">says:</span>'), $author) ?>
                        <?php edit_comment_link(__('(Edit)','avia_framework'),'  ','') ?>
    
                        <!-- display the comment metadata like time and date-->
                            <div class="comment-meta commentmetadata">
                                <a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>">
                                    <time <?php avia_markup_helper(array('context' => 'comment_time'));?>>
                                        <?php printf(__('%1$s at %2$s','avia_framework'), get_comment_date(),  get_comment_time()) ?>
                                    </time>
                                </a>
                            </div>
                    </header>

    From what I can tell on the support article I should be inserting the following code somewhere in the above code, but I’m not sure if I’m missing something or just inserting it in the wrong place.

    // Insert rank title
    					if ( $comment->user_id != 0 )
    						echo '<div class="fn authors-rank" style="margin-left:6.071428571rem;">Rank: ' . mycred_get_users_rank( $comment->user_id ) . '</div>';

    I’d really appreciate any assistance you can provide.

    Thanks!

    https://www.ads-software.com/plugins/mycred/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author myCred

    (@designbymerovingi)

    Hey Redsand747.

    Could you show me where in that first piece of code you add the second piece of code? You can insert the second piece of code anywhere as long as you do so inside the comment loop.

    Remember that the second piece of code will only show the rank for comment authors that are registered on your website. If you are a member but for some reason you comment without being logged in or via a different email, then you will have no rank since we don’t know who you are.

    I also see from your second piece of code that you are applying some margin styling to the rank. Make sure that the rank is not hidden or pushed out of sight via CSS.

    Thread Starter Redsand747

    (@redsand747)

    Hey Gabriel,

    Thanks for the reply. I had tried inserting it into the following location as well as a few other spots to try and see if I could get it to display, but no luck.

    Here’s the code:

    <!-- display the comment -->
                <div class='comment_content'>
                    <header class="comment-header">
                        <?php
                        $author = '<cite class="comment_author_name"'.avia_markup_helper(array('context' => 'author_name','echo'=>false)).'>'.get_comment_author().'</cite>';
                        $link = get_comment_author_url();
                        if(!empty($link))
                            $author = '<a href="'.$link.'" '.avia_markup_helper(array('context' => 'comment_author_url','echo'=>false)).'>'.$author.'</a>';
    
                        printf(__('<cite class="author_name heading"'.avia_markup_helper(array('context' => 'comment_author','echo'=>false)).'>%s</cite> <span class="says">says:</span>'), $author) ?>
                        <?php edit_comment_link(__('(Edit)','avia_framework'),'  ','') ?>
    
    // Insert rank title
    					if ( $comment->user_id != 0 )
    						echo '<div class="fn authors-rank">Rank: ' . mycred_get_users_rank( $comment->user_id ) . '</div>';
    
                        <!-- display the comment metadata like time and date-->
                            <div class="comment-meta commentmetadata">
                                <a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>">
                                    <time <?php avia_markup_helper(array('context' => 'comment_time'));?>>
                                        <?php printf(__('%1$s at %2$s','avia_framework'), get_comment_date(),  get_comment_time()) ?>
                                    </time>
                                </a>
                            </div>
                    </header>

    Good call on the styling. I removed that just to be sure.

    As for being registered and logged in I double checked this. This user has points from myCRED as a registered user and when I’m commenting it says “Logged in as Redsand747,” so I think that’s correct.

    The file I’m editing is called loop-comments.php, but to be honest I’m not sure I’m inserting the necessary piece of code inside the comment loop as you mentioned… I’m just plopping it in between the code that appears to be displaying the comment authors name and the timestamp.

    Thanks!

    Plugin Author myCred

    (@designbymerovingi)

    Hey.

    Sorry for the delay in my reply but 1.4 has been keeping me busy.

    May I ask, what exactly does your code do? Does it return the users rank title or returns absolutly nothing? The reason I am asking is because the code you shown here will just output your code “as it”. PHP code needs to be start with <?php and end with ?>.

    So your above code would be:

    <!-- display the comment -->
     <div class='comment_content'>
        <header class="comment-header">
        <?php
                        $author = '<cite class="comment_author_name"'.avia_markup_helper(array('context' => 'author_name','echo'=>false)).'>'.get_comment_author().'</cite>';
                        $link = get_comment_author_url();
                        if(!empty($link))
                            $author = '<a href="'.$link.'" '.avia_markup_helper(array('context' => 'comment_author_url','echo'=>false)).'>'.$author.'</a>';
    
                        printf(__('<cite class="author_name heading"'.avia_markup_helper(array('context' => 'comment_author','echo'=>false)).'>%s</cite> <span class="says">says:</span>'), $author) ?>
                        <?php edit_comment_link(__('(Edit)','avia_framework'),'  ','') ?>
    <?php
    	// Insert rank title
    	if ( $comment->user_id != 0 )
    		echo '<div class="fn authors-rank">Rank: ' . mycred_get_users_rank( $comment->user_id ) . '</div>'; ?>
    
                        <!-- display the comment metadata like time and date-->
                            <div class="comment-meta commentmetadata">
                                <a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>">
                                    <time <?php avia_markup_helper(array('context' => 'comment_time'));?>>
                                        <?php printf(__('%1$s at %2$s','avia_framework'), get_comment_date(),  get_comment_time()) ?>
                                    </time>
                                </a>
                            </div>
                    </header>

    Thread Starter Redsand747

    (@redsand747)

    Hey Gabriel,

    As you may have guessed I don’t have experience with PHP code, which is why I submitted the topic. I can get by with HTML and CSS, but that’s about it.

    As it stands the code isn’t doing anything on my page. I was hoping if I could show what I was attempting to do, you or someone else might be able to help point me in the right direction. I had tried a bunch of different things including wrapping the code snippet (which I assumed would display the users rank) with the <?php ?> tags, but it I was getting the same result… nothing would display.

    The following code snippet had been pulled from last large block of code in this tutorial that you wrote, but to be honest I was pulling a snippet from your code example with my fingers crossed that it was the right code and I was inserting it in the right spot to display a users rank in the comments.

    // Insert rank title
    					if ( $comment->user_id != 0 )
    						echo '<div class="fn authors-rank" style="margin-left:6.071428571rem;">Rank: ' . mycred_get_users_rank( $comment->user_id ) . '</div>';

    Ultimately, that’s my goal… getting a users rank to display under their name in the comments section.

    I had achieved a similar result in my bbPress forum adding the code snippet that you suggested in this thread to my functions.php, and it worked like a charm.

    I’m open to any way I can get the myCRED rank title to display in the comments section ??

    Appreciate all your time.

    All the best,
    Jon

    Plugin Author myCred

    (@designbymerovingi)

    If you can, contact me via the myCRED Contact page so I can have a look at your comments template file as pasting code snippets here only goes so far.

    Plugin Author myCred

    (@designbymerovingi)

    The solution to this issue was to edit the main themes template file as the child template (which we were updating) was not being loaded at all.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Add myCRED Rank to Comments Section’ is closed to new replies.