clanderf
Member
Posted 10 months ago #
When a user logs into my site, I'd like to display a link to their external website (these users gave me the URL of their external website when they registered as users).
I've tried to use the following codes using get_currentuserinfo but I can't get it to work. I'm not that great with PHP so I think I might be screwing something up, but it's really strange.
Here's the first one I tried:
user_url . '); ?>">HERE
And here's the second:
user_url'); ?>">HERE
I'm using the get_currentuserinfo elsewhere on the template. Does the fact that I'm using the same php "get_currentuserinfo" in 2 different places screw things up?
Please help! I've spent HOURS trying to figure this out!
clanderf
Member
Posted 10 months ago #
Whoops. Here are the 2 pieces of code that tried to use.
<a href="<?php global $userdata; get_currentuserinfo(); echo(' . $userdata->user_url . '); ?>">HERE</a>
<a href="<?php echo get_currentuserinfo('$userdata->user_url'); ?>">HERE</a>
clanderf
Member
Posted 10 months ago #
Any help?? I'd really appreciate it. I'm dying here.
Try with this:
<?php
global $current_user;
get_currentuserinfo();
if($current_user->user_url) :
?>
<a href="<?php echo $current_user->user_url; ?>">HERE</a>
<?php endif; ?>
clanderf
Member
Posted 10 months ago #
Okay, let me try it out real quick.
clanderf
Member
Posted 10 months ago #
Worked perfectly! You're my new favorite person.
Thanks a ton. I REALLY appreciate it.
clanderf
Member
Posted 10 months ago #
This code only displays correctly when it's placed in a template file (php). But we need to actually place it in the body of a page (html). How does one do this? I know this is a pretty rookie question, but I'm a rookie.
I just tried putting it in div tags in the HTML of one of my pages, but it isn't displaying correctly. Here's how I placed it into the body of one of my pages:
<div>
<?php global $current_user; get_currentuserinfo(); if($current_user->user_url) : ?><a href="<?php echo $current_user->user_url; ?>">HERE</a><?php endif; ?>
</div>
You're welcome. Glad you got it resolved.
This is quite tricky but you can try it with this: http://www.sciencetext.com/how-to-make-html-pages-work-like-wordpress.html
And even then I don't know if the global current_user will work.
clanderf
Member
Posted 10 months ago #
Hmm. Well, this page that I'm trying to paste the code into is actually in WordPress (it's a WordPress page--not an outside HTML page).
Do I still need to try this method out or is there an easier way if it's a WordPress page?
I guess I could just create a new php template page with this php code in it?
Thanks again for all your help.
What is not working? Does it show the link or not?
In what theme template file do you want to put it?
Don't use the code (from the link) if it is a regular WordPress Page.
You can put it in most theme template files or create a custom Page template for it
clanderf
Member
Posted 10 months ago #
It doesn't show the link at all and it's not clickable. It just shows part of the code as actual text. In fact, it just says: "user_url) : ?>"
I tried the code that you gave me and put it in the header php template, so I know that it works just fine in php template. I guess I can just create a custom page template. Just not sure how to integrate the code into the body of the page doing this (I just know how to place php code in the header/footer/sidebar...not the body of the page).
I'll play around with it and will figure it out though.
Thanks a ton.
If I use this code it works:
<div>
<?php global $current_user; get_currentuserinfo(); if($current_user->user_url) : ?><a href="<?php echo $current_user->user_url; ?>">HERE</a><?php endif; ?>
</div>
Maybe you pasted it in the wrong place. Try pasting it somewhere else.
clanderf
Member
Posted 10 months ago #
So strange. I pasted that same exact code in a blank page that uses every page template I have, and it still won't work correctly.
Check out how it displays: http://www.vinovirtuoso.com/link-test-page
However, when I paste it as a header link, it works just fine.
I think there must be something in my page templates that is screwing it up once the code rests in an actual page. Or something in my header template that specifically makes it work correctly...
Can you paste the content from your template file in a pastebin, submit it and give a link to it here.
clanderf
Member
Posted 10 months ago #
All righty. Here we go.
Here is the link to the WordPress page template that we are using. We have a few different page templates, but the code isn't working on ANY of them, and this is the page template where we need to place the code to have the link with the user's url, so this is the page template that we're concerned about really.
As I said, the code is working in the header but not in the actual WordPress pages. Thus, I figured that it might be useful to paste in the code for our header as well, in case there's something in the header that is clearly allowing the code to work in the header, or perhaps there's some kind of code in the header that is making the page template malfunction. So here's the code to my header as well:
http://pastebin.com/MEdcWyX3
clanderf
Member
Posted 10 months ago #
Whoops. Here is the link to the custom PAGE TEMPLATE. The link to the HEADER TEMPLATE is in the post above.
Page PHP Template link:
clanderf
Member
Posted 10 months ago #
Damn it. Not sure why the link paste function isn't working. Here's the link:
http://pastebin.com/3xa5jd53
clanderf
Member
Posted 10 months ago #
Any idea what the problem might be, keesie?
I feel like I should maybe close and re-post this issue because it's really a new issue altogether, which is "Why won't this PHP script work when pasted into a WordPress page, but it seems to work when posted in the header php template?"
clanderf
Member
Posted 10 months ago #
Nevermind! I figured it out. I just needed to install the Exec-PHP plugin, which allows one to execute PHP script in WordPress pages.
It worked great.
Thanks again for all of your help, keesie! I'm going to go ahead and close this issue now.