Title: Conditional author include on single.php
Last modified: August 18, 2016

---

# Conditional author include on single.php

 *  [DianeV](https://wordpress.org/support/users/dianev/)
 * (@dianev)
 * [18 years, 10 months ago](https://wordpress.org/support/topic/conditional-author-include-on-singlephp/)
 * I’ve spent many hours on this, and searched the forums and the Web for every 
   combination of terms I can think of.
 * What I’m trying to do is, on **single.php**, call an include for a particular
   author (the include contains a blurb). What I have so far is below, but I can’t
   seem to exclude all other authors, or include only that author — it displays 
   for every author:
 *     ```
       <?php if (the_author_ID !=('2') ) { ?>
       <?php include (TEMPLATEPATH . '/joe.php'); ?>
       <?php } ?>
       ```
   
 * I’ve tried it with other other tags, like the_author, but I get the same type
   of result. Can anyone lend a hint?
 * Obviously, we could just manually add the author’s blurb into her every post,
   but that makes it difficult to change the blurb if her info changes.

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

 *  [jbbrwcky](https://wordpress.org/support/users/jbbrwcky/)
 * (@jbbrwcky)
 * [18 years, 10 months ago](https://wordpress.org/support/topic/conditional-author-include-on-singlephp/#post-591714)
 * Have you tried the_author_ID() ? (the brackets are the thing)
 *  Thread Starter [DianeV](https://wordpress.org/support/users/dianev/)
 * (@dianev)
 * [18 years, 10 months ago](https://wordpress.org/support/topic/conditional-author-include-on-singlephp/#post-591797)
 * Thanks. Yes, I tried `the_author_ID()` — which puts the author’s ID number (and
   the joe include) after every post regardless of author.
 * Same with `the_author_ID(4)`. Also tried various author-related tags I could 
   find. The result was that either the thing wouldn’t display at all, or it displayed
   on every post regardless of author.
 * I’m wondering if this just can’t be done on single.php with author tags. Or whether
   it needs some sort of nested tags that are beyond what I can do.
 *  [ferrie=differentieel](https://wordpress.org/support/users/researcher/)
 * (@researcher)
 * [18 years, 9 months ago](https://wordpress.org/support/topic/conditional-author-include-on-singlephp/#post-591937)
 * i wondered why this is not working?
    is the **is_author** filter perhaps disabled?
 *  [ferrie=differentieel](https://wordpress.org/support/users/researcher/)
 * (@researcher)
 * [18 years, 9 months ago](https://wordpress.org/support/topic/conditional-author-include-on-singlephp/#post-591939)
 * to be shure that my storie here is true i tested this code:
 * `<?php if (is_single() && is_author('1')) { include (TEMPLATEPATH . '/single-
   author1.php'); } elseif (is_single() && is_author('2')) { include (TEMPLATEPATH.'/
   single-author2.php'); } else { printf(__('Sorry, this is not working.')); } ?
   >`
 * first in the index.php. that did not respond into a result i had in mind: author_1
   had to show in the left column, author_2 in the right column. the ordenairy single.
   php shows up at the center.
 * then i tried one level higher and put this code into the header.php nothing at
   all.
 * question: why do we have a [Conditional Tags](http://codex.wordpress.org/Conditional_Tags)
   page in the codex?
    or is there someone who discovered the magick of the **is_author**
   trick?
 *  [natalie](https://wordpress.org/support/users/natalie/)
 * (@natalie)
 * [18 years, 1 month ago](https://wordpress.org/support/topic/conditional-author-include-on-singlephp/#post-591973)
 * I’ve tried to do something similar to this, which is how I found this thread.
   The way I understand `is_author` though is that it means “if we’re on an author
   page”, then narrowing it down, “if we are on _john’s_ author page”. Outside of
   author pages, there’s no way to say “if _this post_ is by john”.
 * The only thing I’ve been able to do is with CSS:
 * `<div class="single" id="<?php the_author_login(); ?>">`
 * Then, style that page differently:
 * `#john div.blurb { styles for john here }`
 * What you _could_ do maybe is put the include there but say `display:none`, then`
   display:block` just for john.
 *  [natalie](https://wordpress.org/support/users/natalie/)
 * (@natalie)
 * [18 years, 1 month ago](https://wordpress.org/support/topic/conditional-author-include-on-singlephp/#post-591974)
 * btw, this tip works great in the body tag as well, setting a class/id to the 
   body based on whatever page you’re on, then using CSS to display/style things
   at will.
 * On my sites I essentially have this (but much more involved):
 * `<body id="<?php echo $slug; ?>" class="<?php if(is_single()) { echo 'single 
   by-'; the_author_login(); } ?>">`
 * Which gives me something like this:
 * `<body id="post-slug" class="single by-john">`
 * oh yeah, slug relies on another piece of code in the `<head>`:
 *     ```
       <?php
           $post_id = get_post($post->ID); // get current post or page
           $slug = $post_id->post_name; // define its slug as $slug
       ?>
       ```
   
 * hope that helps. I’ve had a number of headaches to get these things to work, 
   but it’s beautiful that WP allows us such freedom to do all of this. 🙂
 *  [natalie](https://wordpress.org/support/users/natalie/)
 * (@natalie)
 * [18 years, 1 month ago](https://wordpress.org/support/topic/conditional-author-include-on-singlephp/#post-591975)
 * oh! i had a hunch just now and tried something and it worked! Try this:
 *     ```
       <?php
       $by_john = false;
       if($post->post_author == '1') {
       $by_john = true;
       }
       ?>
   
       // then inside the loop...
   
       <?php if($by_john) { ...do stuff for john... } ?>
       ```
   
 * Change the number 1 to john’s author ID

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

The topic ‘Conditional author include on single.php’ is closed to new replies.

## Tags

 * [conditional tags](https://wordpress.org/support/topic-tag/conditional-tags/)
 * [is_author](https://wordpress.org/support/topic-tag/is_author/)

 * 7 replies
 * 4 participants
 * Last reply from: [natalie](https://wordpress.org/support/users/natalie/)
 * Last activity: [18 years, 1 month ago](https://wordpress.org/support/topic/conditional-author-include-on-singlephp/#post-591975)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
