• Hi,

    I want to show a different theme for each author in my WordPress blog. I want it to work for posts as well as pages. The thing is, I can’t get it to work, with one exception. I used the next code.

    <?php
    if (is_author('Rick')) {include(TEMPLATEPATH . '/rick_header.php');}
    elseif (is_author('Sabine')) {include(TEMPLATEPATH . '/sabine_header.php');}
    elseif (is_author('Nicole')) {include(TEMPLATEPATH . '/nicole_header.php');}
    elseif (is_author('Paula')) {include(TEMPLATEPATH . '/paula_header.php');}
    else {include (TEMPLATEPATH . '/header.php');}
    ?>

    When I go to the archive for the Author on http://www.mysite.nl/author/authorname it shows the theme I want it to show for each user. But it doesn’t work on any other page, not on single.php, not on the pages I generated, nothing. It just doesn’t work.

    Does anyone know what I’m missing here? I must overlook something, because it works on the author archive page, but that’s the only page it works on.

    Thanks!
    Casper

Viewing 5 replies - 1 through 5 (of 5 total)
  • it works on the author archive page

    this is axactly what is_author() is supposed to do; see: http://codex.ww.wp.xz.cn/Function_Reference/is_author

    to make it work on single.php (and page.php) you would need to get the author information from the post (i.e. the author name) and compare it with your list.

    Thread Starter CSPR

    (@cspr)

    Ah, fair enough. Then my next question would be: how do I get the “author name” from the post/page I’m at?

    $author_name = get_the_author(); will get you the author name:
    http://codex.ww.wp.xz.cn/Function_Reference/get_the_author

    integrated into the if statements, this might work:

    <?php if( is_singular() || is_archive() ) :
    $author_name = get_the_author(); 
    
    if ($author_name == 'Rick' || is_author('Rick')) {include(TEMPLATEPATH . '/rick_header.php');}
    elseif ($author_name == 'Sabine' || is_author('Sabine')) {include(TEMPLATEPATH . '/sabine_header.php');}
    elseif ($author_name == 'Nicole' || is_author('Nicole')) {include(TEMPLATEPATH . '/nicole_header.php');}
    elseif ($author_name == 'Paula' || is_author('Paula')) {include(TEMPLATEPATH . '/paula_header.php');}
    else {include (TEMPLATEPATH . '/header.php');}
    
    endif; ?>
    Thread Starter CSPR

    (@cspr)

    Thanks for your help, unfortunately it doesn’t work like this. Should I lose the “is_author” statements for the singular pages? Or should I use the exact code from above?

    you could try to break it into two blocks – one for singular pages, the other for archives;

    and you could check, what $author_name = get_the_author(); returns, by adding a echo $author_name; after the line.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Different themes for each author’ is closed to new replies.