I changed my feed out in the right menu (or down below for those who use Internet Explorer, i still thing it’s wrong for them) to display my liked links from reddit.

Now reddit didn’t make this easy on me. First of all, their standard link in the xml is to their own page, which i kind of stupid, of course i want to link to the page that i liked, in case it’s a self reddit in which case i of course want to link to that.

But however, they do give a link in the description tag in the xml. So it was a matter of parsing the html given in the description to pick out the link.

I use KB Advanced RSS Widget with Wordpress and it comes with some standard options for formatting the xml elements. I added the following to those options:

[sourcecode language=‘PHP’] // finding a link from the reddit feed $reddit = (is_numeric($reddit) && $reddit == “1”) ? (int) $reddit : null; if ($reddit == 1) { preg_match(‘/to(.)href=“(.)“>[link]/‘, $text, $matches); $text = $matches[2]; if(substr($text,0,4) != “http”) { $text = “http://reddit.com".$text; } } [/sourcecode]

So now i can use ^description[opts:reddit=1&bypasssecurity]$ do display the correct link from the reddit feed. Pretty nice actually. If you noted that i use the option bypasssecurity aswell i can tell you that, that is because otherwise, the widget will remove all html tags and i wrote my RegEx to be used with the tags. So if you use my little piece of the script you should use the bypasssecurity option aswell.


tetris