2010-04-01 53 views
1

我正在爲WordPress提供一個簡單的小部件,用於從Twitter提供的RSS源中提取最新的推文。這個小部件解析發佈在推文上的任何鏈接,它還解析提及(即:@用戶名)和趨勢主題(即:#現在)。對於這三種情況,它會創建指向某些Twitter功能的鏈接。XHTML 1.1文檔中的嵌套超鏈接

例如:

"Hi @UserA, check out the song Foo from FooBar that I'm listening, 
it's awesome. #nowplaying" 

它將解析成這樣:

Hi <a href="http://twitter.com/UserA">@UserA</a>, check out the song 
Foo from FooBar that I'm listening, it's awesome. 
<a href="http://twitter.com/#search?q=nowplaying">#nowplaying</a> 

現在,現在我需要一個全球性的鏈接添加到整個郵件,就像這樣:

<a href="http://twitter.com/UserA/statuses/1234567890"> 
Hi <a href="http://twitter.com/UserA">@UserA</a>, check out the song 
Foo from FooBar that I'm listening, it's awesome. 
<a href="http://twitter.com/#search?q=nowplaying">#nowplaying</a> 
</a> 

但是這段代碼並沒有被驗證,反正它也不起作用(瀏覽器似乎不知道該怎麼辦)。

任何建議如何解決這個問題?

回答

2

通過不這樣做。

一個標籤不能嵌套。你既可以鏈接標記添加到的狀態,鏈接回原來的結束,或者你可以做一些額外的解析,使鳴叫是這樣的:

<a href="http://twitter.com/UserA/statuses/1234567890"> 
Hi </a><a href="http://twitter.com/UserA">@UserA</a>, <a href="http://twitter.com/UserA/statuses/1234567890">check out the song 
Foo from FooBar that I'm listening, it's awesome.</a> 
<a href="http://twitter.com/#search?q=nowplaying">#nowplaying</a> 

這樣每一個字,這不是一個鏈接將鏈接到原始狀態,但我不知道這是您的最佳選擇。

0

在推文日期周圍設置鏈接,並將其放在文本之前或之後。

2

我會使用JavaScript作爲全局鏈接。如果你在郵件前面有一個項目符號或者其他東西,把鏈接放在那裏,當點擊郵件時用JavaScript激活它(該鏈接將作爲沒有JS支持的用戶的鏈接)

如果你需要有整個事物即使沒有JS也是可點擊的,你需要將它分成多個鏈接,這些鏈接覆蓋了內容鏈接之間的東西。