Help Sought: Do you know Wordpress and PHP?
By Steve Poland • March 17, 2007
UPDATE: Chip Haynor, Sr. Project Consultant, of CentreSource in Nashville was able to send me the needed code — Thanks Chip!!! Here’s the code: comment_classes.txt. After the “foreach” loop of the comments (should look something like “< ? php foreach ($comments as $comment) : ? >“), enter the code in that text file. The first “if” section checks if the commenter is the post author, and sets the comment class if true (and bypasses the author level check). Otherwise, it checks the author level, and assigns the appropriate term to the $comment_class.
You can add more cases by copying the three lines (the “case”, the “$comment_class” declaration, and the “break;”). As you can see with the case 1 and 2, you can have multiple values for a given declaration (Case 1 AND Case 2 will both become “contrib”).
Then, you just need to put into your HTML code in the appropriate place.
This is a shameless plea for help from my readers — maybe one of you knows Wordpress and PHP. If you aren’t a programmer, no need to read any further.
My blog currently highlights any comments I make on my posts differently from regular users — so that they stand-out. I want to take this a step further — Wordpress has different user levels and I want to have comments highlighted differently by users in my Wordpress that are designated as ‘Contributor’ (user level = 1).
Thus, what I want to do is:
Currently, any of my comments have the following CSS:
class="comment commentOfficialUser"
Whereas normal users’ comments on my site are:
class="comment "
I want to make any user in my Wordpress that has a user_level of 1, have the following CSS:
class="comment commentContributorUser"
I currently use the Official Comments plugin. The author references what I’m wanting to do, but he never implemented it into his plugin.
Here is an excerpt of the code from my Template’s “comment” PHP: comments.txt
Thus, you need to grab the user level of the commenter (if they exist in my Wordpress as a user; and then check what their user level is — 9 is the admin; 1 is the contributor). Here is the code I thought would work (I removed use of Official Comments all together), but I must be missing something, because it didn’t work — but I think I’m very close with that code.
Otherwise, you could likely modify the Official Comments source code — in an optimal world, it’d be great to have the ability to specify a CSS class for each of the 5 user types in Wordpress (Admin, Author, Editor, Contributor, Subscriber).
I sent that code to Rachel and her reply included this, which may help — but I’m not a programmer, so not sure how/where this would fit in.
Feel free to comment in comments if you guys have any input.
Here are some additional resources I found:
http://codex.wordpress.org/Roles_and_Capabilities
http://codex.wordpress.org/User_Levels
http://codex.wordpress.org/Function_Reference/get_userdata
http://fortes.com/projects/wordpress/postlevels/
http://wordpress.org/support/topic/72709
http://www.irakrakow.com/wptips/2006/05/04/role-manager-plugin-fine-tune-wordpress-authorization/
Related posts:
- Wordpress Theme Wanted: 3-column I’m looking for a Wordpress theme for a new site I’m going to be launching. I’m looking for one that can display your typical final 2 columns of ads much like TechCrunch, Read/Write Web, JohnChow,...
- IM Bots: (Almost) Real-Time Blog Chat via IM This post got me thinking about how you could integrate IM into blogs. Currently, if people communicate about a topic/post, they post a comment. Almost in real-time, others can be alerted of the new comments...
- Blogging a Web Start-Up with Expert Insight Ringside Startup has officially launched. Here are the basics on this endeavor: I’m raising $20,000 in reader/sponsor contributions to launch a web start-up. Contributor participation entitles you to vote on actual business decisions — the...
- IDEA #7 – Video Comments Plugin for Blogs Michael Arrington, TechCrunch 1/14/07: “For the blogger crowd, it would be very useful to have a plugin that works directly with the standard comments feature that allows users to leave text, audio, or audio/video comments...
- Ringside Startup Launches! 60 days to raise $20,000 I’m excited to announce the launch of Ringside Startup! The gist of the website is that I’m raising $20,000 from readers/sponsors — to enlighten everyone’s entrepreneurship education. With the contributions, I’m going to launch...
Related posts brought to you by Yet Another Related Posts Plugin.
Comments
5 Responses to “Help Sought: Do you know Wordpress and PHP?”
Got something to say?



Rachel was close on a new reply. Here was my reply to her:
Rachel,
I believe that is taking the userdata of the current logged in user? Thus, I’m seeing ‘userlevel-10′ when I’m logged in… when I log-out, I get ‘userlevel-’. I think you’re close!!
Here’s where I had put that code:
<?php foreach ($comments as $comment) : ?><?php
global $userdata;
get_currentuserinfo();
?>
<li class=\"comment userlevel-<?php echo $userdata->user_level; ?>\" id=\"comment-<?php comment_ID() ?>\">
Here it is, your moment of Zen:
<ol class="commentlist">
<?php foreach ($comments as $comment) : $author_meta = new WP_User($comment->user_id); $author_level = $author_meta->roles['0']; ?>
<!--<li class="<?php echo $oddcomment; ?>" id="comment-<?php comment_ID() ?>">-->
<li class="comment <?php if($author_level != null) { echo "comment" . ucwords($author_level) . "User"; } ?>" id="comment-<?php comment_ID() ?>">
<?php if(function_exists("MyAvatars")) MyAvatars(); ?>
<cite><?php comment_author_link() ?></cite> Says:
<?php if ($comment->comment_approved == '0') : ?>
<em>Your comment is awaiting moderation.</em>
<?php endif; ?>
<br />
<small class="commentmetadata"><a href="#comment-<?php comment_ID() ?>" title=""><?php comment_date('F jS, Y') ?> at <?php comment_time() ?></a> <?php edit_comment_link('e','',''); ?></small>
<?php comment_text() ?>
</li>
<?php /* Changes every other comment to a different class */
if ('alt' == $oddcomment) $oddcomment = '';
else $oddcomment = 'alt';
?>
<?php endforeach; /* end for each comment */ ?>
</ol>
Hey Steve,
I’m going to look into this this afternoon/evening, right after I get back from the hardware store with a new angle stop for the hot water side under my kitchen sink. I installed a new faucet yesterday, and the old valve had some stripped threading making it impossible to hook up my dishwasher. And I will not code, as my business partner so eloquently posted yesterday my girl code with dish pan hands!
If you recall our conversation when you told me about your use of Official Comments plugin on your site, you’ll know that I want to have it at our site as well. I like your concepts of differentiating, visually users of different levels. If it’s not solved by later today, I’ll jump in with what you’ve done thus far and see if we can’t whip up something we can both use, and release out there as well!
Go Boldly!
Chip Haynor, Sr. Project Consultant, of CentreSource in Nashville was able to send me the needed code — Thanks Chip!!! I’ll update the post to include a link to the code.
Talk about “Ask and you shall receive”!
Looking forward to seeing and using that code. Thanks Steve and Chip!