-1

I know that Jetpack's 'widget visibility' option can be used to display widgets on specific author pages. I would like to be able to do this in my theme's template file.

The list of conditional tags has options to see if one is on a specific author's archive page but not, seemingly, to check who the specific author of a post is.

This is basically what I want to do:

If author is Mr. Incredible, show some html. If author is Mrs. Incredible, show different html.

Is this possible? I imagine it should be but I haven't been able to find any how to on it yet.

2 Answers2

0

Sure! Your problem statement is a great start. Let's translate it into actual code:

If author is Mr. Incredible, show some html. If author is Mrs. Incredible, show different html.

Becomes:

if ( is_author('Mr. Incredible Nickname or ID') ) {
    // echo some HTML
} elseif ( is_author('Mrs. Incredible Nickname or ID') ) {
    // echo different HTML
} else {
    // if neither, echo something else
}

The code should be readable, just like the problem statement.

You can read more about is_author() in the Codex.

Additionally, if you need to check the author of individual posts, you can use get_the_author().

rnevius
  • 26,578
  • 10
  • 58
  • 86
  • Thanks for the 'translation' - that looks to be exactly what I'm looking for as I can do it for all authors on the site in one go. Do you recommend just putting the php into single.php or calling a template file like Fatih Sari suggested above? – Chez Ballou Jan 03 '15 at 20:00
  • That's really up to you. Personally, I don't see a problem sticking it directly into your **single.php**, or whatever file is running it – rnevius Jan 04 '15 at 08:11
  • I'll see what works best - I'm using a premium theme and it using a lot of custom functions. – Chez Ballou Jan 04 '15 at 16:11
  • Great, please close up this question by selecting an answer. – rnevius Jan 05 '15 at 07:13
0
  1. You can get post author ID.
  2. With use it, get author nickname or etc...
  3. And check your want with this.

Tip for you:

in single.php

<?php
   $ID = $post->post_author;
   $nickname = get_the_author_meta('nickname', $ID);
   if($nickname == "fors")
      include(TEMPLATEPATH . '/fors-template.php');
   else
      include(TEMPLATEPATH . '/single-default.php');
?>
Fatih SARI
  • 435
  • 4
  • 21