Support » Fixing WordPress » Help upgrading comments.php to wp2.7 standard PLEASE!

  • Okay, after trying to twist my mind around the new way comments work in WP 2.7+ (yeah, I just discovered they had changed now, I’m late), I’ve decided to ask for help.

    Basically, I am pretty comfortable with CSS and HTML, but PHP is a bit beyond me. If it’s well commented I can usually decipher what it does, but in this case it’s just too much to wrap my brain around. My goal is simply to upgrade my theme to present standards.

    My theme is totally unique, I built it starting two years ago using a very simple theme as a base, and customized it greatly. Right now I have been busy cleaning out the code, and removing as much “hacked” markup from the theme and into the CSS as possible. Most of my theme’s code is very clean and as simple as possible, as I am almost obsessive about minimalism in this regard, so I have succeeded with every section except comments.php. This page features some heavy modifications and more complex PHP that I added in a copy and paste fashion but just barely understand. I just don’t know translate what I have into the newer way of doing things.

    My main concern is how to keep my avatar image that appears in the author comments only. I really don’t want to open up avatars for every user. I don’t know how to achieve this using just the CSS hooks, and I don’t really want to have to use gravatar just for this.

    Here is my present comments.php

    <?php // Do not delete these lines
    if (!empty($_SERVER['SCRIPT_FILENAME']) && 'comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
    	die ('Please do not load this page directly. Thanks!');
    if ( post_password_required() ) {
    	echo 'This post is password protected. Enter the password to view comments.';
    /* This variable is for alternating comment background */
    $oddcomment = 'alt';
    $admincomment = 'class="admin" ';
    <!--display number of reponses and post title-->
    <?php if ($comments) : ?>
    <h3><?php comments_number('No Responses', 'One Response', '% Responses' );?> to “<?php the_title(); ?>”</h3>
    <!--end display number of reponses and post title-->
    <!--start comment list--><ul id="comments">
    <!--begin one comment-->
    <?php foreach ($comments as $comment) : ?>
    <?php $comment_type = get_comment_type(); ?>
    <?php if($comment_type == 'comment') { ?>
    <li <?php if (1 == $comment->user_id) {
      echo $admincomment;
      } else {
      echo $oddcomment;
    } ?>id="comment-<?php comment_ID() ?>">
    <?php if (1 == $comment->user_id) {
      echo '<img style="border: 0; float: right;" src="" alt="avatar" width="50" height="50" />';
    } ?>
    <?php comment_author_link() ?> Says:
    <?php if ($comment->comment_approved == '0') : ?>
    <em>Your comment is awaiting moderation.</em>
    <?php endif; ?>
    <br />
    <!--comment date and edit link-->
    <a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date('F jS, Y') ?> at <?php comment_time() ?></a> <?php edit_comment_link('edit','',''); ?>
    <!--end comment date and edit link-->
    <!--begin comment text-->
    <?php comment_text() ?>
    <!--end comment text-->
    <!--end one comment-->
    <?php /* Changes every other comment to a different class */
    	if ('alt' == $oddcomment) $oddcomment = '';
    	else $oddcomment = 'alt';
    <?php } /* End of is_comment statement */ ?>
    <?php endforeach; /* end for each comment */ ?>
    <!--end comment list-->
    <?php foreach ($comments as $comment) : ?>
    <?php $comment_type = get_comment_type(); ?>
    <?php if($comment_type != 'comment') { ?>
    <li><?php comment_author_link() ?><?php comment_text() ?></li>
    <?php } ?>
    <?php endforeach; ?>
    <?php else : // this is displayed if there are no comments so far ?>
      <?php if ('open' == $post->comment_status) : ?>
    		<!-- If comments are open, but there are no comments. -->
    	 <?php else : // comments are closed ?>
    		<!-- If comments are closed. -->
    		<p>Comments are closed.</p>
    	<?php endif; ?>
    <?php endif; ?>
    <?php if ('open' == $post->comment_status) : ?>
    <h3>Submit Comment</h3>
    <?php if ( get_option('comment_registration') && !$user_ID ) : ?>
    <p>You must be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php the_permalink(); ?>">logged in</a> to post a comment.</p>
    <?php else : ?>
    <!--begin comments form-->
    <p><b>Be nice. Please use your real name or a nickname. This site uses KeywordLuv. Enter YourName@YourKeywords in the Name field to take advantage. DO NOT use keywords in the name field without including your name. I do review all comments, any that are obvious spam for the purpose of getting a linkback WILL have the link removed.</b></p>
    <form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
    <?php if ( $user_ID ) : ?>
    <p>Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?action=logout" title="Log out of this account">Logout &raquo;</a></p>
    <?php else : ?>
    <div class="formleft"><label for="author">Your Name:</label></div><div class="formright"><input type="text" name="author" class="textinput" id="author" value="<?php echo $comment_author; ?>" size="30" tabindex="1" /> <small><?php if ($req) echo "(required)"; ?></small></div>
    <div class="formleft"><label for="email">Your Email:</label></div><div class="formright"><input type="text" name="email" class="textinput" id="email" value="<?php echo $comment_author_email; ?>" size="30" tabindex="2" /> <small>(will not be published) <?php if ($req) echo "(required)"; ?></small></div>
    <div class="formleft"><label for="url">Your Website:</label></div><div class="formright"><input type="text" name="url" class="textinput" id="url" value="<?php echo $comment_author_url; ?>" size="30" tabindex="3" /></div>
    <?php endif; ?>
    <div class="formleft"><label for="comment">Your Comment:</label></div><div class="formright"><textarea name="comment" class="textinput" id="comment" cols="50" rows="12" tabindex="4"></textarea></div>
    <div class="formright"><input name="submit" type="submit" class="submit" id="submit" tabindex="5" value="Submit" /></div>
    <input type="hidden" name="comment_post_ID" value="<?php echo $id; ?>" />
    <?php do_action('comment_form', $post->ID); ?>
    <!--end comments form-->
    <?php endif; // If registration required and not logged in ?>
    <?php endif; // if you delete this the sky will fall on your head ?>

    And here is the relevent portion of my style.css

    #comments li {
    	border: solid #5d5b35 1px;
    	list-style-type: none !important;
    	margin-bottom: 10px !important;
    	padding: 0px 5px 0px 5px !important;
    #trackbacks li {
    	list-style-type: none !important;
    	padding: 0px 5px 0px 5px !important;
    #comments li.admin {
    	background: transparent url(images/filter30.png);
    #comments, #trackbacks {
    	font-size: 12px; /*font-family: Verdana, Helvetica, Arial, Sans-Serif;*/

    This is what it looks like in action:

    So how can I translate this mess into the clean and simple code available in wp2.7+ without losing my locally hosted, admin only, avatar

Viewing 3 replies - 1 through 3 (of 3 total)
  • Well, I gave up a night of sleep and managed to hack it together myself, minus the adding a locally hosted image to just the author comments, so gravtars are now in effect.

    Still wold be curious if it is possible to do what I suggested though.



    Forum Moderator

    If you check the source code of the comments, you should see that there’s a bypostauthor class added to post author comments only. So, in theory, you could hide non-author images via CSS using something like:

    #commentlist img {display:none}
    #commentlist .bypostauthor img {display:inline;}

    Thanks esmi,

    So obvious, and yet never thought of it.

    The actually issue I had though was more that I wanted to avoid using gravatar and keep my image local, and didn’t see a way to do that with the new comment loop.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Help upgrading comments.php to wp2.7 standard PLEASE!’ is closed to new replies.