• Hi Lester

    I’m trying to customise how the plugin displays, but I’ve ran into a bit a problem I don’t know how to fix 🙂

    In the comments template instead of using :

    <?php if(function_exists('the_ratings')) { the_ratings(); } ?>

    I want to use this :

    <?php global $current_user, $post;
     $user_comment_count = get_comments(array('user_id' => $current_user->ID, 'post_id'=>$post->ID) ); ?>
    
    <?php if($user_comment_count) { 
    	echo '<h2>Thank you for your review,  please leave a star rating.</h2>';
       the_ratings();  
    } else {
    	echo' <h2>Leave a review first you may then give a star rating.</h2>'; 
        comment_form(array('class_submit'=>'button'));
    } 
    ?>

    Which basically hides the rating, until a comment has been made. This works just fine and as expected, however when doing this, the JSON-LD doesnt output and so when using the https://search.google.com/structured-data/testing-tool/u/0/

    It doesnt show any schema, if i revert back to the original code it works fine.

    Please could you advise where im going wrong.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Lester Chan

    (@gamerz)

    Yes, it is by design, the plugin only outputs the markup when in a loop and not in the comment section/template.

    There are just too many possibilities on where to place the code, I need to make the plugin as generic as possible and hence the decision.

    You can manually output the markup if you wish. Feel free to refer to how I do here it https://github.com/lesterchan/wp-postratings/blob/master/wp-postratings.php#L1160-L1221

    This is the furthest I can help you with as I don’t provide support for plugin customization =)

    Thread Starter rivmedia

    (@rivmedia)

    Thanks for that reply Lester,

    I did see it was designed for the main loop. But I can’t understand why your code :

    <?php if(function_exists('the_ratings')) { the_ratings(); } ?>

    Works exactly how we want it to, in exactly the same location. But our code :

    <?php global $current_user, $post;
     $user_comment_count = get_comments(array('user_id' => $current_user->ID, 'post_id'=>$post->ID) ); ?>
    
    <?php if($user_comment_count) { 
    	echo '<h2>Thank you for your review,  please leave a star rating.</h2>';
       the_ratings();  
    } else {
    	echo' <h2>Leave a review first you may then give a star rating.</h2>'; 
        comment_form(array('class_submit'=>'button'));
    } 
    ?>

    Doesn’t work, I actually think its something in our code which is missing rather than being a loop problem ? We’ve also tested our code in the main loop and have the same problem. I was hoping you could see something obvious as to why its not working.

    Plugin Author Lester Chan

    (@gamerz)

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

The topic ‘Help customising :)’ is closed to new replies.