Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have my own function called breadcrumbs(). In it I call is_author() to determine whether I am on an author page. If true I would like to know which author's page I am on. I tried the_author(), but nothing came up. I looked through the WP codex also. Can someone please help?

share|improve this question

3 Answers 3

up vote 1 down vote accepted

Call echo $GLOBALS['wp_query']->query_vars['author_name']; and it should show you the author.

You can also echo $GLOBALS['wp_query']->post->post_author; or echo $GLOBALS['wp_query']->queried_object->post_author;.

hope i didn't mix up with arrays and objects.

share|improve this answer
    
Your first suggestion worked. Your second suggestion returned '1' which I assumed to be the author ID. The third one returned nothing. I like your first solution best because it seems that rolling through posts as in my solution would be inefficient. –  mrtsherman Mar 24 '11 at 19:45
    
See new Answer. This will help you fix my code from above and get what you exactly need. –  kaiser Mar 25 '11 at 5:55

So I figured it out by looking at the author.php file included with the twenty ten theme. Apparently you need to first gain access to the posts before creating breadcrumb. Following code worked for me:

if (is_author()) {      
    the_post();
    echo '<a href="">Author Archive for '.get_the_author().'</a>';
    rewind_posts(); //or first post will be cut off
}
share|improve this answer

Because people are often confused about how to get data from global objects/vars

Use this to get an insight view of what you can use from the current request/wp_query.

function inspect_wp_query() 
{
  echo '<pre>';
    print_r($GLOBALS['wp_query'])
  echo '</pre>';
}
add_action( 'template_redirect' ); // Query on public facing pages
add_action( 'admin_notices' ); // Query in admin UI

Btw:

    // this:
    global $wp_query;
    $wp_query;
    // is the same as
    $wp_query;
    // and as this:
    $GLOBALS['wp_query'];

// You can do this with each other global var too, like $post, etc.

How to actually get the data:

// Example (not the best one)
Object WP_Query -> post stdClass -> postdata Array

// How to get the data:
// Save object into var
$my_data = new WP_Query; // on a new object
// or on the global available object from the current request
$my_data = $GLOBALS['wp_query'];

// get object/stdClass
$my_post_data = $my_data->post;
// get Array
$my_post_data = $my_data['post'];
share|improve this answer
    
Thank-you. Very useful. –  mrtsherman Mar 25 '11 at 13:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.