WordPress Tips & Tricks: Author Highlighting through Theme Options
In my post, WordPress Tips & Tricks: Author Comment Highlighting, I mentioned the downfalls to using that particular method: having to manually change the email address in comments.php.
The one downfall to using this method, is that you’ll need to dive into comments.php if you ever need to change your address, or your theme users will need to, and not everyone is in-the-know enough not to get lost or just don’t know what they’re doing.
The best way around this is either using a plugin or using theme options. When releasing an updated version of the Simple In Pink theme, I decided to play around with planetOzh’s WordPress Theme Toolkit, to try and add a few options into the theme, so anyone that wanted to use the theme, wouldn’t have to go into the themes template files. One of the options I successfully added was author highlighting. This post will give a run down of how to use the Theme Toolkit to add author highlighting to your own themes.
What you need:
- Read WordPress Tips & Tricks: Author Comment Highlighting (not neccessary but would help)
- A WordPress theme
- WordPress Theme Toolkit (download it and read ALL of the documentation)
- Any good text editor
- Somewhere to test your theme
You need to check out the WordPress Theme Toolkit. My suggestion would be to read through the documentation to get an idea of how it works otherwise you may get lost while reading this. Follow the instructions in the download section. You need to copy themetoolkit.php and functions.php to your theme directory.
Open functions.php and find the following line:
‘mytheme’, /* Make yourself at home :
‘mytheme’ should be changed to something identifiable and unique to your theme. For this example, let’s have a make believe theme called ’something’. Change ‘mytheme’ to ’something’ so it looks like the following:
’something’, /* Make yourself at home :
Make sure you save as you go along. Next, find the following:
’setting1′ => ‘Setting One ## This is setting one.’,
’setting2′ => ‘Stuff {textarea|6|50} ## Enter some text’,
’setting3′ => ‘Choice {radio|choice1|Choice One|choice2|Choice Two} ## Chose one.’,
’setting4′ => ‘Multiple choice {checkbox|mc1|happy|Are you Happy ?|mc2|human|Are you Human ?} ## Chose any’,
These are the options and will add them to your themes option page. We’re going to add an option for author highlighting. It’s as simple as changing it to look like the following:
‘authorhighlight’ => ‘Author Highlight ## Enter your email address for author highlighting’,
Any left over options (’setting2′, ’setting3′ etc) can be removed, or you can leave them to create other theme options.
Next up, we need to create a function. Find the following (at the bottom of functions.php):
function creditcard() {
global $mytheme;
print “My Credit Card Number is : “;
print $mytheme->option['creditcard'];
}
Obviously this won’t do much since we aren’t actually using a credit card option ;). We need to change this to something similar to the following:
function something_authorhighlight() {
global $something;
return $something->option['authorhighlight'];
}
All of the something in there is the name of our theme. If you name your theme Super Duper Pinky, it will probably be something like $superduperpinky and superduperpinky_authorhighlight, depending on what you entered back at ‘mytheme’. Now we’re finished with functions.php.
Next we need to call the email address in comments.php so we can highlight the comment. The technique is pretty much the same as in WordPress Tips & Tricks: Author Comment Highlighting. Open comments.php and find the following line:
<li class=”<?php echo $oddcomment; ?>” id=”comment-<?php comment_ID() ?>”>
Change this to:
<li class=”<?php if ($comment->comment_author_email == mytheme_option() ) echo ‘author’; else echo $oddcomment; ?>” id=”comment-<?php comment_ID() ?>”>
Change mytheme_option to your theme name and your author highlight option name. If we go by the example I used, it would be something_authorhighlight. Obviously, like in my previous post, echo ‘author’ is the class in the CSS that will highlight the author’s comment. Add something to your style.css file that is similar to the following:
.author {
background:#FFFFFF url(images/someimage.gif) top repeat-x !important;
color:#000000 !important;
}
Using !important will override the other comment styling for the author comment only.
That’s basically it. Be sure to test the options thoroughly in your theme to make sure they work correctly. There’s not much point in adding to your theme if it doesn’t work. It basically defeats the purpose of it.
Very clever use of the toolkit :D
Nice wrap up !
(and commenter above Mike is a spammer :)
@Ozh: I did figure as much :P I’ve removed their comment. Darn those sneaky spammers!
[...] comment highlighting. Author Comment Highlighting and Author Highlighting Through Theme Options provide information about styling author’s [...]
[...] comment highlighting. Author Comment Highlighting and Author Highlighting Through Theme Options provide information about styling author’s [...]
[...] comment highlighting. Author Comment Highlighting and Author Highlighting Through Theme Options provide information about styling author’s [...]
[...] comment highlighting. Author Comment Highlighting and Author Highlighting Through Theme Options provide information about styling author’s [...]
[...] Comment Highlighting and Author Highlighting Through Theme Options gives detailed information on styling author’s [...]
[...] Comment Highlighting and Author Highlighting Through Theme Options provide information about styling author’s [...]
very good tutorial i like it very useful :)