nyssabrowndesign

Welcome to my redesign - okay, I'm kidding. This is a temporary "interval" theme. It didn't take too long. I am still redesigning but mean while, I'm putting this up. Why? I have some other projects I need to get stuck into, which reduces my time a little. I'd also like to contemplate my redesign a bit as I'm currently unsure about its direction. To understand more and the reasons behind my interval theme, read I haven't redesigned, but stay tuned!

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:

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.

10 Responses to “WordPress Tips & Tricks: Author Highlighting through Theme Options”

  1. } Mike wrote }

    Very clever use of the toolkit :D

    # June 29th, 2007 at 4:30 pm
  2. } Ozh wrote }

    Nice wrap up !

    (and commenter above Mike is a spammer :)

    # June 29th, 2007 at 7:31 pm
  3. } Nyssa wrote }

    @Ozh: I did figure as much :P I’ve removed their comment. Darn those sneaky spammers!

    # June 29th, 2007 at 9:58 pm
  4. [...] comment highlighting. Author Comment Highlighting and Author Highlighting Through Theme Options provide information about styling author’s [...]

    # June 30th, 2007 at 10:32 am
  5. [...] comment highlighting. Author Comment Highlighting and Author Highlighting Through Theme Options provide information about styling author’s [...]

    # July 3rd, 2007 at 1:26 pm
  6. [...] comment highlighting. Author Comment Highlighting and Author Highlighting Through Theme Options provide information about styling author’s [...]

    # September 24th, 2007 at 9:09 pm
  7. [...] comment highlighting. Author Comment Highlighting and Author Highlighting Through Theme Options provide information about styling author’s [...]

    # October 11th, 2007 at 6:28 am
  8. [...] Comment Highlighting and Author Highlighting Through Theme Options  gives detailed information on styling author’s [...]

    # October 25th, 2007 at 6:01 pm
  9. [...] Comment Highlighting and Author Highlighting Through Theme Options provide information about styling author’s [...]

    # January 7th, 2008 at 9:12 am
  10. } immy00100 wrote }

    very good tutorial i like it very useful :)

    # April 1st, 2008 at 7:38 am

Leave a Reply