Support » Fixing WordPress » Trying to tweak comments.php

  • Resolved snoogly


    I am building an educational web site. One element of the site is that all users must write comments on certain pages. However, I only want these comments to be actually visible to admin (me), and one other user (this user would be different on every page).

    I am trying to tweak comments.php so that the comments area is only shown to specified users (using user_ID).

    This is the ‘if’ statement I am using (on this page, I need user ID #2 to be able to see the comments):

    <?php if($user_ID == 2 || $user_ID == 1): ?>
    <?php endif; // end if $user_ID ?>

    That works, but the problem is that on other pages I need a different user_ID in the ‘if’ statement.

    Of course I can’t create a different comments.php for every page! ~ so my question is:

    How can I easily change the user_ID value in the ‘if’ statement, depending on the page?

Viewing 6 replies - 1 through 6 (of 6 total)
  • You can try something like…

    <? if(($user_id = 1 and $post_id=8) or ($user_id = 2 and $_post_10)) { ?>

    The problem is that you will have to update the file in every new post…

    Yes, the problem is the large number of pages involved ~ 50. Easy to tweak comments.php for one 1 page/1 user, but not for 50 pages and 10 users!

    Thanks to patricioqb I think I will be able to do what I want by matching userid’s to postid’s.

    Something like this would do it – but how should I correctly list the 5 pages? Commas don’t work, and neither does ‘or’.

    <?php if($user_ID == 1 || $user_ID == 2 && $post->ID == 5,7,10 ,11,12: ?>

    Can a WP/PHP guru tell me how to correctly list those 5 pages?


    I am not WP guru, but I think I am PHP Guru 😛

    What do you want? User 1 and 2 to see 5,7,10,11 and 12 post?

    It should be:

    if(($user_ID == 1 OR $user_ID == 2) AND ($post->ID == 5 or $post->ID == 7 or $post->ID == 10 or $post->ID == 11 or $post->ID == 12))

    Sweet. Yes indeed I want those users to see comments on those specific posts, I just didn’t know how to list them properly. But thanks to you, I do now!

    This is great, as at last I can pull my course on presentation skills out of Moodle and into WP.

    The reason I need to tweak the comments.php, is that I upload videos of students’ speeches – and other students write comments about them. The trick is that I need them to write their comments ‘blind’, without reading comments written by other students. The only people who can read the comments are me (the teacher), and the student who’s speech is being commented on.

    Thanks again patricioqb

    Perfect then!

    You are welcome! 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Trying to tweak comments.php’ is closed to new replies.