Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Author tags on page with no author WordPress

  • SOLVED

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.

Answers (3)

2010-07-31

Mike Schinkel answers:

@Viktor: Are you wanting author info to show for each post that is returned as a search result for a post, i.e. inside "[[LINK href="http://codex.wordpress.org/The_Loop"]]The Loop[[/LINK]]?"


Viktor Nagornyy comments:

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.


Mike Schinkel comments:

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...


Mike Schinkel comments:

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.


Mike Schinkel comments:

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); ?>


Viktor Nagornyy comments:

Wish I knew it was that easy =)

2010-07-31

Lew Ayotte answers:

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


Viktor Nagornyy comments:

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.


Lew Ayotte comments:

And the search.php file calls the sidebar?


Viktor Nagornyy comments:

Yes.


Lew Ayotte comments:

Hrm... what is the site URL?


Lew Ayotte comments:

Is there only one author for your site?


Viktor Nagornyy comments:

Yes, just me.


Lew Ayotte comments:

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; ?>


Lew Ayotte comments:

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; ?>


Viktor Nagornyy comments:

Mike below got it. Just needed an author ID.

2010-07-31

Pippin Williamson answers:

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.


Viktor Nagornyy comments:

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.


Pippin Williamson comments:

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.