• What’s the best way to create different single.php’s for specific authors. I saw a tutorial that was written a while ago that was for categories but I’m wondering if there’s a new way to do it for authors.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The WordPress Template Hierarchy does not include a single-$author.php template.

    You could create a custom archive index page for a given author, using author-$nicename.php or author-$id.php template files, but to create a custom single post on a per-author basis, you’ll need to get your hands a bit dirty with filtering body_class() and/or post_class() in order to add an author-specific CSS class to the HTML body tag and/or the post div.

    Thread Starter enderpal444

    (@enderpal444)

    All I’m really trying to do is display a certain ad unit for a specific author with their posts. Is there an easier solution for that?

    Moderator keesiemeijer

    (@keesiemeijer)

    try it with something like this in single.php:

    if($posts[0]->post_author == 1){ // author ID
    // do stuff
    }

    Thread Starter enderpal444

    (@enderpal444)

    @keesiemeijer

    Ok say I have an ad which is ‘<script>…</script>’.

    How can use that code you gave to show three different scripts for 3 different authors inside a div?

    Moderator keesiemeijer

    (@keesiemeijer)

    Try it with this:

    <?php if($posts[0]->post_author == 1) : ?>
     <script></script> <!-- script for author ID 1 -->
     <?php elseif($posts[0]->post_author == 5) : ?>
     <script></script> <!-- script for author ID 5 -->
     <?php elseif($posts[0]->post_author == 8) : ?>
     <script></script> <!-- script for author ID 8 -->
     <?php endif; ?>

    Thread Starter enderpal444

    (@enderpal444)

    Works absolutely perfect! Thx so much for that keesie!

    Moderator keesiemeijer

    (@keesiemeijer)

    You’re welcome. Glad you got it resolved.

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

The topic ‘Custom Single.php for specific author’ is closed to new replies.