Hello,
I hope there's a helpful PHP expert who can help me with the following:
I've successfully pulled my latest twitter post into my WP page, but the links doesn't work. Instead of the link address alone, it's linking to [my domain]+[link]
See for yourself at http://jlangvad.com (at the bottom of the page)
The code I've added is:
----------------
<div class="blockBotDiv2">
<div class="grayTitle">LATEST TWEET</div>
<div class="smallBotText">
<?php
$username = "jlangvad"; // Your twitter username.
$prefix = ""; // Prefix - some text you want displayed before your latest tweet.
$suffix = " Read all entries at "; // Suffix - some text you want display after your latest tweet.
$feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=1";
function parse_feed($feed) {
$stepOne = explode("<content type=\"html\">", $feed);
$stepTwo = explode("</content>", $stepOne[1]);
$tweet = $stepTwo[0];
$tweet = str_replace("<", "<", $tweet);
$tweet = str_replace(">", ">", $tweet);
return $tweet;
}
$twitterFeed = file_get_contents($feed);
echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);
?>
<a href="http://twitter.com/jlangvad" target="_blank">twitter.com/jlangvad</a>
</div>
---------------
How can I change this?
Best,
Jacob Langvad
Showing Twitter post in WP blog works, but the links don't
Moderator: General Moderators
Re: Showing Twitter post in WP blog works, but the links don't
This is what I see in your source:
So somewhere you're encoding your quotes.
Code: Select all
<a href="http://bit.ly/7mwIxC">http://bit.ly/7mwIxC</a>Re: Showing Twitter post in WP blog works, but the links don't
Hi Jackpf,
The problem is that when you click on a link, eg. http://bit.ly/7mwIxC, it links to http://jlangvad.com/"http://bit.ly/7mwIxC", instead of http://bit.ly/7mwIxC
The same problem is with the hashtag links.
Is the problem the "? <a href="http://bit.ly/7mwIxC">http://bit.ly/7mwIxC</a>
How can I remove that quote?
Jacob
The problem is that when you click on a link, eg. http://bit.ly/7mwIxC, it links to http://jlangvad.com/"http://bit.ly/7mwIxC", instead of http://bit.ly/7mwIxC
The same problem is with the hashtag links.
Is the problem the "? <a href="http://bit.ly/7mwIxC">http://bit.ly/7mwIxC</a>
How can I remove that quote?
Jacob
Last edited by jlangvad on Mon Nov 30, 2009 9:57 am, edited 1 time in total.
Re: Showing Twitter post in WP blog works, but the links don't
Yeah, and the cause of that is because of what I just posted.
Because there are no quotes around the URL, it thinks that ""http://bit.ly/7mwIxC"" is the URL. Since it is not prefixed with "http://" it thinks it's a relative URL, as in, a link to another page on your site, so it'll go to http://yoursite.com/"http://bit.ly/7mwIxC".
Change the encoded quotes to real quotes.
----------
Ahh, I see you've edited your post ;p
Yeah, that's the problem. Are you running htmlentites() or htmlspecialchars() on it somewhere? Or converting " to "? Have a look through your code. I don't think you've posted the relevant code here though... What code is actually generating that link?
Because there are no quotes around the URL, it thinks that ""http://bit.ly/7mwIxC"" is the URL. Since it is not prefixed with "http://" it thinks it's a relative URL, as in, a link to another page on your site, so it'll go to http://yoursite.com/"http://bit.ly/7mwIxC".
Change the encoded quotes to real quotes.
----------
Ahh, I see you've edited your post ;p
Yeah, that's the problem. Are you running htmlentites() or htmlspecialchars() on it somewhere? Or converting " to "? Have a look through your code. I don't think you've posted the relevant code here though... What code is actually generating that link?
Re: Showing Twitter post in WP blog works, but the links don't
Hi again, yes, sorry, I edited my answer after re-reading your post.
Great, now I understand the problem.
The link is generated through bit.ly (in TweetDeck for instance) and posted to my twitter feed: http://twitter.com/jlangvad/status/6168105713 - The tweet on my website is a exact copy of that text pulled from twitter.
I am not sure about the other things you ask about; htmlentites(), htmlspecialchars(). How can I check this?
Thank you so much for your time
Jacob
Great, now I understand the problem.
Now we are approaching the boundaries of my limited expertizeYeah, that's the problem. Are you running htmlentites() or htmlspecialchars() on it somewhere? Or converting " to "? Have a look through your code. I don't think you've posted the relevant code here though... What code is actually generating that link?
The link is generated through bit.ly (in TweetDeck for instance) and posted to my twitter feed: http://twitter.com/jlangvad/status/6168105713 - The tweet on my website is a exact copy of that text pulled from twitter.
I am not sure about the other things you ask about; htmlentites(), htmlspecialchars(). How can I check this?
Thank you so much for your time
Jacob
Re: Showing Twitter post in WP blog works, but the links don't
Well, the functions i mentioned are just functions to convert special characters to their html entities.
It looks as though you're running one of these functions on your link, hence the converted quotes.
For example, run this:
Have a look at the source and you'll see how it's being converted.
You're probably doing something similar in your code. So either have a look through, or post the exact code that generates the links here and I'll have a quick look.

It looks as though you're running one of these functions on your link, hence the converted quotes.
For example, run this:
Code: Select all
echo '<a href="http://google.com">google</a>'; // should work OK
echo '<br>';
echo '<a href='.htmlentities('"http://google.com"').'>google</a>'; // should link to the current site /"http://google.com", because of the encoded quotesYou're probably doing something similar in your code. So either have a look through, or post the exact code that generates the links here and I'll have a quick look.
Re: Showing Twitter post in WP blog works, but the links don't
The link is created from the code I posted in the beginning:
I've pasted the code into a widget via 'Daiko's Text'. Each of the five colons in the footer are separate widgets.
I got the code from this page: http://www.instantshift.com/2009/05/25/ ... ress-blog/
I have no expertise in programming, so, if it's not possible to fix easily, I guess, I will have to hire someone to do it.
Thanks for your time, I really appreciate.
Jacob
<div class="blockBotDiv2">
<div class="grayTitle">LATEST TWEET</div>
<div class="smallBotText">
<?php
$username = "jlangvad"; // Your twitter username.
$prefix = ""; // Prefix - some text you want displayed before your latest tweet.
$suffix = " Read all entries at "; // Suffix - some text you want display after your latest tweet.
$feed = "http://search.twitter.com/search.atom?q=from:" . $username . "&rpp=1";
function parse_feed($feed) {
$stepOne = explode("<content type=\"html\">", $feed);
$stepTwo = explode("</content>", $stepOne[1]);
$tweet = $stepTwo[0];
$tweet = str_replace("<", "<", $tweet);
$tweet = str_replace(">", ">", $tweet);
return $tweet;
}
$twitterFeed = file_get_contents($feed);
echo stripslashes($prefix) . parse_feed($twitterFeed) . stripslashes($suffix);
?>
<a href="http://twitter.com/jlangvad" target="_blank">twitter.com/jlangvad</a>
</div>
I've pasted the code into a widget via 'Daiko's Text'. Each of the five colons in the footer are separate widgets.
I got the code from this page: http://www.instantshift.com/2009/05/25/ ... ress-blog/
I have no expertise in programming, so, if it's not possible to fix easily, I guess, I will have to hire someone to do it.
Thanks for your time, I really appreciate.
Jacob
Re: Showing Twitter post in WP blog works, but the links don't
You're not creating any links there...so I can't really see what you're doing.