我的WordPress的網站是由我自己寫的插件放慢。該插件從不同站點上的RSS源加載事件。懶惰加載一個RSS提要在PHP
我禁用了該插件,它在Google Page Speed中的差異爲20。
我該如何在Ajax或Javascript中加載RSS feed?
的代碼,我有:
$rss = simplexml_load_file(get_option('capu_url'));
foreach ($rss->channel->item as $item) {
echo '<h4><a href="'. $item->link .'">' . $item->title . "</a></h4>";
//echo "<p>" . $item->description . "</p>";
$dom = new DOMDocument;
$dom->strictErrorChecking = FALSE ;
libxml_use_internal_errors(true);
$dom->loadHTML($item->description);
$xpath = new DOMXPath($dom);
$nodes = $xpath->query('//ul[@class="ee-event-datetimes-ul"]'); // get <ul>'s with class 'up'
foreach($nodes as $node) { // loops through each <ul>
foreach($node->getElementsByTagName('li') as $li) { // loops through the <li>'s
echo $li->nodeValue . "<br/>\n"; // echo's the <li> elements
你能告訴我們你已經有的代碼嗎? –
當然,我會馬上添加它 –