BlogCFC Author Comments

Tags: BlogCFC
Word Count: 289

One common design technique you will see on blogs is the distinct separation between a user comment and an author comment. Just by taking a quick glance at a group of comments you should be able to see where the Author has responded. In BlogCFC this is snap to do and I want to walk you through how I did it on my blog. Here is a quick snapshot of what my comments look like now in case they change in the future.

This first thing we need to do is setup our structure for our css. I took this completely out of the code so you could see it raw. You will notice that we have a container for all comments (comments) along with a comments section header (h3). Next we have a container for individual comments (comment). Each comment will have a head (commet-head) that contains information like the current comment number, the posters name and when the comment was posted. Finally each comment will have a body (comment-body) which is the actually comment. When we have multiple comments the single comment will just repeat itself.

<div id="comments">
<h3>Comments</h3>
<div class="comment">
   <div class="comment-head">
      #1 Posted By: Jake Munson Posted On: 12/29/07 11:13 AM
   </div>
   <div class="comment-body">
      My problem with services like this is they just give you a snapshot of your site. I am usually worried about how JavaScript works, so these services are useless for that.
   </div>
</div>
</div>

Now that we have an idea of the structure for a single comment lets look at the structure for our example above. Below we have added the author comment. The first thing you will notice is that our first comment now has a class of comment-odd. This is because I changed the style for odd number comments, I think this just makes it easier to read. We will get into the code later for now we will just focus on the structure. Next I have added a class around the post number, for the author posts you will see that the class changes from comment-number to comment-number-author. Finally at the end of the comment head for the author post we have a class author-comment with the words Author Comment to easily distinguish between user and author comments.

<div class="comment-odd">
   <div class="comment-head">
      <span class="comment-number">#1</span> Posted By: Jake Munson Posted On: 12/29/07 11:13 AM
   </div>
   <div class="comment-body">
      My problem with services like this is they just give you a snapshot of your site. I am usually worried about how JavaScript works, so these services are useless for that.
   </div>
</div>

<div class="comment">
   <div class="comment-head">
      <span class="comment-number-author">#2</span> Posted By: Dan Vega Posted On: 12/29/07 11:43 AM | <div class="author-comment">Author Comment</div>
   </div>
   <div class="comment-body">
      I would not disagree with you but I do think this fills one void. We know the real power behind the application is functionality but the first thing a client will see is the design and for those of who us who live on FF this service keeps us on the same page as our clients.
   </div>
</div>

</div>

Now that we understand the structure of how we are going to set it up we need to write some code. BlogCFC makes it very easy to distinguish between users and the author by requiring a email address when posting a comment. This is the field we will use to pick out our authors. Our code below is where we actually loop the comments for an entry. The first thing we do is look at the current row and if it is an odd row we use a grayish background defined in the comment-odd class. Next we want to style the comment number if this an author post we can do that by checking the comments.email variable, since all posts require an email address this will tell us if this post is from the author. I have just hard coded my email address in there but I am sure you could throw it in the config and grab it as a property. Finally we do the same thing for the words Author Comment. We check to see if comments email address equals that of our authors and if it does display our class.

<cfloop query="comments">
<div class="comment<cfif currentRow MOD 2>-odd</cfif>">
   <div class="comment-head">
      <span class="comment-number<cfif comments.email EQ 'danvega@gmail.com'>-dan</cfif>">###currentRow#</span>
      Posted By: <cfif len(comments.website)><a href="#comments.website#" rel="nofollow">#name#</a><cfelse>#name#</cfif>
      Posted On: #application.localeUtils.dateLocaleFormat(posted,"short")# #application.localeUtils.timeLocaleFormat(posted)#   
      <cfif comments.email EQ "danvega@gmail.com">| <div class="author-comment">Author Comment</div></cfif>
   </div>
   <div class="comment-body">
      #paragraphFormat2(replaceLinks(comment))#                     
   </div>
</div>
</cfloop>

Here is the css I use on my site in case anyone is interested.
#comments .comment {
   margin:0px 0px 8px 0px;
   padding:6px;
   border:1px solid #ddd;
}
#comments .comment-odd {
   margin:0px 0px 8px 0px;
   padding:6px;
   background-color:#eee;
   border:1px solid #ddd;
}

#comments .comment-head {
   display:block;
}
#comments .comment-body {
   display:block;
   margin-top:8px;
   margin-left:25px;
   padding-left:10px;
   border-left:4px solid #ddd;
}
#comments .comment-number {
   font-family:Arial, Helvetica, sans-serif;
   font-size:11px;
   color:#404040;
   font-weight:bold;
   padding:2px;
}
#comments .comment-number-author {
   font-family:Arial, Helvetica, sans-serif;
   font-size:13px;
   color:#DE1909;
   font-weight:bold;
   padding:2px;
}
#comments .author-comment {
   font-size:12px;
   color:#DE1909;
   font-weight:bold;
   display:inline;   
}

This is by no means full proof because of course you could have cases where there are multiple authors for a single blog. Another problem is if a user decides to be a funny guy and put your email address as his. This however should work for most authors. Enjoy!

Comments

#1 Posted By: Anony Moose Posted On: 12/29/07 2:07 PM |
Author Comment
What happens if we fill out the e-mail address field as "danvega@gmail.com"?
#2 Posted By: Anony Moose Posted On: 12/29/07 2:07 PM
Looks like it's easy to become the author....!
#3 Posted By: Dan Vega Posted On: 12/29/07 2:09 PM |
Author Comment
Last Paragraph :)


Comments are not allowed for this entry.

Copyright © 2007 Dan Vega | BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.