...

View Full Version : WordPress script not working correctly :S



bennyy007
06-29-2010, 09:05 AM
Hello,

I made this script to check to wherever the 'Author Bio' is empty or not if empty then display a little message saying 'This author does not have a description yet...' but if the author does have a description then it will display their bio.

But the problem I'm having is that it displays the 'Author Bio' also the message that is shown when the Author doesn't have a bio??? :confused:

Here's the code:



<?php
if ( the_author_meta('description') == '' ) {
echo '<em>This author does not have a description yet...</em>';
} else if(the_author_meta('description')) { echo the_author_meta('description'); }
?>


Yet very simple code, but can't understand why it's doing that unless WordPress is doing something to it... If anyone could help me solve this I would greatly appreciate it :)

Thanks in advance!

mlseim
06-29-2010, 12:21 PM
Just a shot in the dark ... else instead of else-if ...

Try:


<?php
if ( the_author_meta('description') == "" ) {
echo "<em>This author does not have a description yet...</em>";
}
else {
echo the_author_meta('description');
}
?>

bennyy007
06-29-2010, 12:31 PM
Thanks for the reply mlseim,

But that doesn't seem to solve it I've tried so many ways with this, but yet still no luck... :(

xconspirisist
06-29-2010, 12:35 PM
<?php

$description = the_author_meta('description');

if (empty($description)) {
echo '<em>This author does not have a description yet...</em>';
} else {
echo $description;
}

?>


If that does not work, look at the output of this script to see what wordpress is actually giving you:



$description = the_author_meta('description');
var_dump($description);

bennyy007
06-29-2010, 12:40 PM
I'll try that now...

bennyy007
06-29-2010, 12:42 PM
It gives me this: NULL :confused:

kar2905
06-29-2010, 12:49 PM
I suggest you have a look here :
http://codex.wordpress.org/Function_Reference/the_author_meta

bennyy007
06-29-2010, 12:59 PM
What am I meant to be looking at? I've been on that page yet provides the correct variables to use and so on but nothing checking against them :confused: but thanks though :)

kar2905
06-29-2010, 01:05 PM
I guess you should use :
get_the_author_meta()

Check this :

NOTE: Use get_the_author_meta() if you need to return (not display) the information.

bennyy007
06-29-2010, 01:10 PM
Ah that well yes in a way but that's like checking against all, I could be very wrong on that but and I've tried it but still does what it did before. Not really sure why WP doesn't like this kind of method of checking :confused:

kar2905
06-29-2010, 01:25 PM
There is something wrong you are doing. Which file are you editing ?

bennyy007
06-29-2010, 01:38 PM
Single.php

kar2905
06-29-2010, 02:25 PM
Try debugging with Firebug or just view the source and see where the author bio is displayed.

bennyy007
06-29-2010, 02:31 PM
Well I know where it is as I've manually put it in the single.php file...

The code:



<!-- get the author bio -->
<div class="authorprofile">
<div id="authorInfo">
<div id="aheading" class="style1">About the Author</div>
<div id="aboutauthor">
<?php

$description = the_author_meta('user_description');

if (empty($description)) {
echo '<em>This author does not have a description yet...</em>';
} else {
echo $description;
}

?>
</div>
<div id="wrapbtm">
<div id="followontwit"><a href="<?php the_author_meta('twitter'); ?>">Visit <?php the_author_meta('first_name'); ?> on Twitter</a></div>
<div id="visitauthpage"><a href="<?php the_author_meta('user_url'); ?>">Visit <?php the_author_meta('first_name'); ?>'s Website</a></div>
</div>
</div>
<div id="authorPic">
<?php echo get_avatar( get_the_author_email(), '100' ); ?></div>
</div>

kar2905
06-29-2010, 02:37 PM
Try :




$description = get_the_author_meta('user_description');


By the way, what is displayed if the user doesn't have a bio ?

xconspirisist
06-29-2010, 05:35 PM
Have you tried using my original code example, substituting the function call "the_author_meta" with "get_the_author_meta"? That is almost certain to work.

In my code example, it checks the variable using the "empty" function.

bennyy007
06-29-2010, 11:05 PM
Hey,

Sorry for the late response...Had a power cut most of the day :mad: that said that code solved the issue so thank you very much for your kind help much appreciated :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum