Forum Moderators: coopster

Message Too Old, No Replies

send a authors name to google search query

using php

         

youfoundjake

10:17 pm on Feb 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In my wordpress blog, the variable is
comment_author_link()
and i want to pass the name to google so that someone can see how many times that name appears on the internet. For example, if search for the word test, this is the url:
[google.com...]

I'd like to pass the author's name, not "comment_author_link".

Anyone have any ideas?

Ben878

10:23 pm on Feb 3, 2008 (gmt 0)

10+ Year Member



Try this


<?php
$author=comment_author_link();
echo "<a href='http://www.google.com/search?hl=en&q={$author}'> Search authors name via google</a>";
?>

[edited by: Ben878 at 10:23 pm (utc) on Feb. 3, 2008]

youfoundjake

11:30 pm on Feb 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



For some reason, its not passing the username to google. the target url turns out to be just
[google.com...]

As I am new to this, should there maybe be a post statement sent to google?

wheelie34

1:14 pm on Feb 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You don't need to POST to google

the variable $author what does it contain? try to print it out IE

$author=comment_author_link();

print "$author";# see if its a string
print_r ($author);# see if its an array

If it contains what you are looking for (the authors name) then you can build on it, see what you get first

HTH

youfoundjake

5:28 pm on Feb 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hey wheelie34,

I put this block in.


<?php
$author=comment_author();
print "$author";# see if its a string
print_r ($author);# see if its an array
?>

I misposted earlier, it should be comment_author.
When the page displays, the name of the poster appears. but only if the $author=comment_author(); is not commented out.
Both the print statements display nothing.

whoisgregg

6:42 pm on Feb 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In Wordpress, those functions don't return the data, they echo it. So trying to assign the return of the function to a variable just isn't going to work (and, once you know what the functions do, is generally unnecessary.)

Inside a PHP block:

<?php
echo '<a href="http://www.google.com/search?hl=en&q=';
comment_author();
echo '"> Search authors name via google</a>';
?>

Outside a PHP block:

<a href="http://www.google.com/search?hl=en&q=<?php comment_author(); ?>"> Search authors name via google</a>

youfoundjake

7:12 pm on Feb 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Sweet, it works, (of course)
I made a little mod, later I will look at making the author's name the hyperlink;

See how popular
<?php
echo comment_author();
?> is on
<?php
echo '<a href="http://www.google.com/search?hl=en&q=';
comment_author();
echo '" target="_blank">Google</a>';
?>

yea, sloppy, I know, but I'm getting there.

whoisgregg

8:05 pm on Feb 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd say the method of doing it outside the PHP block is simpler (the way Wordpress sets it up):

See how popular <a href="http://www.google.com/search?hl=en&q=<?php comment_author(); ?>"><?php comment_author(); ?></a> is on Google!

youfoundjake

8:16 pm on Feb 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



perfecto, thanks gregg, u rock.

whoisgregg

9:42 pm on Feb 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad I could help. :)