WP PHP Loop doesn’t display information at end

I have a very simple php loop here (see below) and would like the the two like and dislike counters to appear after the img class “yearofstudy”. However the text does not appear after the image. Even if it is placed after the actual HTML.

The Like and Dislike on Comments has to be inside tis function for it to work as it creates a WP loop where they display. Basically, I need help re-arranging this so the like and dislikes appear in the loop but after the image.

Read More

Any help is greatly appreciated, I have been staring at this for hours and have looked every online and still yet to find anything.

// Add the comment meta (saved earlier) to the comment text 
// You can also output the comment meta values directly in comments template  

add_filter( 'comment_text', 'modify_comment');
function modify_comment( $text ){

    $plugin_url_path = WP_PLUGIN_URL;

    if( $commenttitle = get_comment_meta( get_comment_ID(), 'title', true ) ) {
        $commenttitle = '<strong>' . esc_attr( $commenttitle ) . '</strong><br/>';
        $text = $commenttitle . $text;
    } 

    if( $commentrating = get_comment_meta( get_comment_ID(), 'rating', true ) ) {
        $commentrating = '<p class="comment-rating">    <img src="'. $plugin_url_path .
        '/ExtendComment/images/'. $commentrating . 'star.gif" class="yearofstudy" /></p><br />';


        $text = $text . $commentrating;
        return $text;   

    // LIKE AND DISLIKE ON COMMENTS     
    if(function_exists('like_counter_c')) { like_counter_c('text for like'); }

    if(function_exists('dislike_counter_c')) { dislike_counter_c('text for dislike'); }     
    }

}

EDIT:

Although the answers supplied by RecoveringSince2003 does work and makes the like and dislike display, it doesn’t allow the functions to appear after the html image yearofstudy. It appears before and this is not what i am after.

For an example see here, make sure you scroll down to see the comments/reviews: http://universitycompare.com/universities/anglia-ruskin-university

Related posts

Leave a Reply

1 comment

  1. At the first glance, you have

    if( $commentrating = get_comment_meta( get_comment_ID(), 'rating', true ) ) {
        $commentrating = '<p class="comment-rating">    <img src="'. $plugin_url_path .
        '/ExtendComment/images/'. $commentrating . 'star.gif" class="yearofstudy" /></p><br />';
    
        $text = $text . $commentrating;
        return $text;   // <-- terminating the execution
    
        // following code is never being executed
        // LIKE AND DISLIKE ON COMMENTS     
        if(function_exists('like_counter_c')) { like_counter_c('text for like'); }
        if(function_exists('dislike_counter_c')) { dislike_counter_c('text for dislike'); }     
    }
    

    So. the return statement is terminating the execution of the function and rest of the code after return is never being reached. I don’t know what/how these function calls are working but if you want to execute these if(function_exists('like_counter_c')) lines then move your return statement after these lines, something like

    $text = $text . $commentrating;
    if(function_exists('like_counter_c')) { like_counter_c('text for like'); }
    if(function_exists('dislike_counter_c')) { dislike_counter_c('text for dislike'); }
    return $text;
    

    Update :

    Add some style in your image tag, like (there are other ways too by modifying the **yearofstudy** class)

    <img src="'. $plugin_url_path .
        '/ExtendComment/images/'. $commentrating . 'star.gif" class="yearofstudy" style="float:right" />