Support » Theme: Hitchcock » Author comments hook

  • Resolved indeedably

    (@indeedably)


    Hi Anders. Thanks for creating and maintaining the beautiful Hitchcock theme.

    Feature request: Add a CSS class hook to allow styling of comments made by post authors, distinguishing them from comments made by readers.

    In functions.php you currently have:

    <h4 class="comment-title">
    	<?php echo get_comment_author_link(); ?>
    	<span><a class="comment-date-link" href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ) ?>" title="<?php echo get_comment_date() . ' at ' . get_comment_time(); ?>"><?php echo get_comment_date( get_option( 'date_format' ) ); ?></a>
    	<?php
    	if ( $post == get_post( $post->ID ) ) {
    		if ( $comment->user_id === $post->post_author )
    		echo ' &mdash; ' . __( 'Post Author', 'hitchcock' );
    	}
    	?>
    	</span>
    </h4>

    There is probably a more elegant way to achieve it, but the replicating the if block used to output the POST AUTHOR text gets the job done. A simple addition along the lines of the following would allow users to style the H4 when it is the author replying.

    <h4 class="comment-title<?php
    	if ( $post == get_post( $post->ID ) ) {
    		if ( $comment->user_id === $post->post_author )
    		echo ' author';
    	}
    	?>">
    	<?php echo get_comment_author_link(); ?>
    	<span><a class="comment-date-link" href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ) ?>" title="<?php echo get_comment_date() . ' at ' . get_comment_time(); ?>"><?php echo get_comment_date( get_option( 'date_format' ) ); ?></a>
    	<?php
    	if ( $post == get_post( $post->ID ) ) {
    		if ( $comment->user_id === $post->post_author )
    		echo ' &mdash; ' . __( 'Post Author', 'hitchcock' );
    	}
    	?>
    	</span>
    </h4>

    The problem with trying to use the existing byuser hook is that while it successfully styles the first comment by the post author, all subsequent comments in the thread (regardless of whether or not they are made by the post author) are similarly styled.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Theme Author Anders Norén

    (@anlino)

    Hi @indeedably,

    You can solve this by using the following targeting in CSS:

    .bypostauthor > div.comment .comment-title {
        color: red;
    }

    That will only hit the comment posted by the post author.

    — Anders

    indeedably

    (@indeedably)

    Thanks Anders, that works perfectly.

    Given this is possible, shouldn’t the php code:

    <?php
    if ( $post == get_post( $post->ID ) ) {
    	if ( $comment->user_id === $post->post_author )
    	echo ' &mdash; ' . __( 'Post Author', 'hitchcock' );
    }
    ?>

    Be some CSS code like the following?

    .bypostauthor > div.comment .comment-title::after { 
      content: " &mdash; Post Author";
    }

    That would allow for the “ – post author” text to be altered/removed without needing to modify the php code.

    Thanks again 🙂

    Theme Author Anders Norén

    (@anlino)

    @indeedably No problem! Theme strings need to be included in the PHP code, using internationalization functions, for them to be translateable through translate.wordpress.org.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Author comments hook’ is closed to new replies.