logo

$5
Author tags on page with no author

Quick, easy question.
I'm using author tags to get information from the profile and gravatar, it works great. But, if a page has no author (search page) information doesn't show up. How can I set author so information shows up? Here's my code:
<a class="alignleft" href="<?php the_author_meta('user_url'); ?>"><?php echo get_avatar( get_the_author_meta('user_email'), '85', '' ); ?></a><?php the_author_meta('description'); ?>


Thanks for your help.

Viktor Nagornyy | 07/31/10 at 4:00pm | Edit


(3) Possible Answers Submitted...

  • avatar
    Last edited:
    07/31/10
    4:14pm
    Lew Ayotte says:

    Have you added the code to the search.php loop?

    • 07/31/10 4:16pm

      Viktor Nagornyy says:

      The code is in sidebar.php, it is placed above all the widgets. Original theme had static text, I placed this from my other theme where it was in single.php. It works fine everywhere but search results page.

    • 07/31/10 4:20pm

      Lew Ayotte says:

      And the search.php file calls the sidebar?

    • 07/31/10 4:26pm

      Viktor Nagornyy says:

      Yes.

    • 07/31/10 4:29pm

      Lew Ayotte says:

      Hrm... what is the site URL?

    • 07/31/10 4:31pm

      Lew Ayotte says:

      Is there only one author for your site?

    • 07/31/10 4:33pm

      Viktor Nagornyy says:

      Yes, just me.

    • 07/31/10 4:41pm

      Lew Ayotte says:

      Yeah, it's because it's not in The Loop...

      If it's just you, try this code:


      $author = get_user_by('slug', 'your_username");
      <a class="alignleft" href="<?php echo $curauth->user_url; ?>"><?php echo get_avatar( get_the_author_meta($curauth->user_email;), '85', '' ); ?></a><?php echo $curauth->user_description; ?>

    • 07/31/10 4:43pm

      Lew Ayotte says:

      oops, I put the wrong quote in there :) and typo'ed the variable

      $curauth = get_user_by('slug', 'your_username');

      <a class="alignleft" href="<?php echo $curauth->user_url; ?>"><?php echo get_avatar( get_the_author_meta($curauth->user_email;), '85', '' ); ?></a>
      <?php echo $curauth->user_description; ?>

    • 07/31/10 4:43pm

      Viktor Nagornyy says:

      Mike below got it. Just needed an author ID.

  • avatar
    Last edited:
    07/31/10
    4:44pm
    Mike Schinkel says:

    @Viktor: Are you wanting author info to show for each post that is returned as a search result for a post, i.e. inside "The Loop?"

    • 07/31/10 4:33pm

      Viktor Nagornyy says:

      Hey Mike,
      No, seems like I missed a bit of information. The code I posted is inside sidebar.php, which places that info above all widgets. search.php calls sidebar. It works well when there's an author. But on search page, it seems to miss it. I just need to set it to one author, me.

    • 07/31/10 4:33pm

      Mike Schinkel says:

      Assuming that you answer "yes" to my question then adding "$post->post_author" as a second parameter to your functions should probably give you what you want, i.e.


      &lt;a class="alignleft" href="&lt;?php the_author_meta('user_url',$post-&gt;post_author); ?&gt;"&gt;
      &lt;?php echo get_avatar( get_the_author_meta('user_email',$post-&gt;post_author), '85', '' ); ?&gt;
      &lt;/a&gt;
      &lt;?php the_author_meta('description',$post-&gt;post_author); ?&gt;


      Let me know...

    • 07/31/10 4:35pm

      Mike Schinkel says:

      Sorry, I post my example after you replied. If you just want it to be for you then you need your author ID (let's assume it is "1") and pass it as the 2nd parameter instead:


      &lt;a class="alignleft" href="&lt;?php the_author_meta('user_url',1); ?&gt;"&gt;
      &lt;?php echo get_avatar( get_the_author_meta('user_email',1), '85', '' ); ?&gt;
      &lt;/a&gt;
      &lt;?php the_author_meta('description',1); ?&gt;


      Hope the helps. Let me know.

    • 07/31/10 4:37pm

      Mike Schinkel says:

      Arrgh! Sorry about the code/html formatting issue. I was trying to out-think the website:


      <a class="alignleft" href="<?php the_author_meta('user_url',1); ?>">
      <?php echo get_avatar( get_the_author_meta('user_email',1), '85', '' ); ?>
      </a>
      <?php the_author_meta('description',1); ?>

    • 07/31/10 4:42pm

      Viktor Nagornyy says:

      Wish I knew it was that easy =)

  • avatar
    Last edited:
    07/31/10
    4:31pm
    Pippin Williamson says:

    Try adding it manually to the search.php page, inside of the loop. I'm going to venture a guess that it doesn't show up there when in the sidebar because there are multiple posts showing up in the search results, and because the author meta call isn't being called from within the loop.

    • 07/31/10 4:35pm

      Viktor Nagornyy says:

      What exactly would I add?
      The site is a new blog with one test post. I just need that code to pull my information, that's it.

    • 07/31/10 4:38pm

      Pippin Williamson says:

      Put this

      <a class="alignleft" href="<?php the_author_meta('user_url'); ?>"><?php echo get_avatar( get_the_author_meta('user_email'), '85', '' ); ?></a><?php the_author_meta('description'); ?>
      into your search.php inside of the loop, so after

      <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>


      and before


      <?php endwhile; else: ?>
      <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
      <?php endif; ?>


      This probably won't give you exactly what you want, but it should tell you what the problem is.

This question has expired.





Current status of this question: Completed