I have a page on my site which shows three code boxes, these are to allow people to paste badges from the site onto their own blog.
I want the badges to link straight back to the users author page, and at the moment i have put "YOUR USER NAME HERE" where the user needs to update the code with their username to make this happen.
This is not ideal.
Is there anyway to make the text inside the code box dynamic, so that it automatically grabs the logged in users username and displays it?
An example of one of the code box codes is:
<textarea style="background: none repeat scroll 0% 0% #f0f0f0; border: 1px solid #cccccc; color: #777777; font-size: 90%; margin: auto; text-align: left; height: 155px; padding: 2px 0pt 2px 5px; display: block; width: 80%;"><a href=" http://dropdeadgorgeousdaily.com/author/YOUR USER NAME HERE"><img title="View My DDGD edit" src="http://dropdeadgorgeousdaily.com/wp-content/uploads/ddgd-widget-300w2.png" width="300" height="250" /></a> </textarea>
Thanks
Gabriel Reguly answers:
Hi kateM82,
global $current_user;
get_currentuserinfo();
echo 'Username: ' . $current_user->user_login . "\n";
echo 'User email: ' . $current_user->user_email . "\n";
echo 'User first name: ' . $current_user->user_firstname . "\n";
echo 'User last name: ' . $current_user->user_lastname . "\n";
echo 'User display name: ' . $current_user->display_name . "\n";
echo 'User ID: ' . $current_user->ID . "\n";
echo 'http://dropdeadgorgeousdaily.com/author/' . $current_user->user_login . "\n";
Regards,
Gabriel
kateM82 comments:
Can you please include it in the codebox code, I would have no idea where to paste this.
Thanks.
Gabriel Reguly comments:
Hi,
Surely, try
<?php
global $current_user;
get_currentuserinfo();
?>
<textarea style="background: none repeat scroll 0% 0% #f0f0f0; border: 1px solid #cccccc; color: #777777; font-size: 90%; margin: auto; text-align: left; height: 155px; padding: 2px 0pt 2px 5px; display: block; width: 80%;"><a href=" http://dropdeadgorgeousdaily.com/author/<?php echo $current_user->user_login; ?>"><img title="View My DDGD edit" src="http://dropdeadgorgeousdaily.com/wp-content/uploads/ddgd-widget-300w2.png" width="300" height="250" /></a> </textarea>
Regards,
Gabriel
kateM82 comments:
Worked perfectly, thanks!
Ehthisham tk answers:
<?php
global $user_ID;
get_currentuserinfo();
$user_info = get_userdata($user_ID);
$user_link = get_author_posts_url($user_id,$user_info->display_name);
?>
<a href="<?php echo $user_link ?>">Username</a>
kateM82 comments:
Can you please include it in the codebox code, I would have no idea where to paste this.
Thanks.
Ehthisham tk comments:
in your example
<textarea style="background: none repeat scroll 0% 0% #f0f0f0; border: 1px solid #cccccc; color: #777777; font-size: 90%; margin: auto; text-align: left; height: 155px; padding: 2px 0pt 2px 5px; display: block; width: 80%;"><strong><a href="<?php echo $user_link ?></strong>"><img title="View My DDGD edit" src="http://dropdeadgorgeousdaily.com/wp-content/uploads/ddgd-widget-300w2.png" width="300" height="250" /></a> </textarea>
ej_emman answers:
Hello kateM82,
I understand what are you trying to make it happen. you want codes in your textbox.
Maybe you should try this.
<?php global $current_user;
get_currentuserinfo(); ?>
<textarea style="background: none repeat scroll 0% 0% #f0f0f0; border: 1px solid #cccccc; color: #777777; font-size: 90%; margin: auto; text-align: left; height: 155px; padding: 2px 0pt 2px 5px; display: block; width: 80%;"><a href=" http://dropdeadgorgeousdaily.com/author/<?php echo $current_user->user_login; ?>"><img title="View My DDGD edit" src="http://dropdeadgorgeousdaily.com/wp-content/uploads/ddgd-widget-300w2.png" width="300" height="250" /></a> </textarea>
ej_emman comments:
tell me if it helps :)