Forums

Different themes for each author (6 posts)

  1. CSPR
    Member
    Posted 1 year ago #

    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

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    it works on the author archive page

    this is axactly what is_author() is supposed to do; see: http://codex.wordpress.org/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.

  3. CSPR
    Member
    Posted 1 year ago #

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

  4. alchymyth
    The Sweeper
    Posted 1 year ago #

    $author_name = get_the_author(); will get you the author name:
    http://codex.wordpress.org/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; ?>
  5. CSPR
    Member
    Posted 1 year ago #

    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?

  6. alchymyth
    The Sweeper
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic