Hướng dẫn RSS trong Drupal

Hướng dẫn RSS trong Drupal

RSS là một định dạng tập tin thuộc họ XML dùng trong việc chia sẻ tin tức Web (Web syndication) được dùng bởi nhiều website tin tức và weblog .Trong bài này ta sẽ nghiên cứu vài cách để lấy tin từ một trang khác bằng RSS

Cách 1:Dùng module aggregator

Mặc định nó chỉ hiện lên 1 trường duy nhất là title.để có thể hiện thêm các trường khác theo ý muốn ta dùng hàm  

theme_aggregator_block_item ,ta viết thêm vào trong file template.php:

function clean_aggregator_block_item($variables) {
<p> $output = '<p><a href="'.check_url($variables['item']->link).'">'.check_plain($variables['item']->title)."</a></p>";
 $output .='<p class="date">'.date("d-m-y", $variables['item']->timestamp).' </p>';</p>
<p> return $output;</p>

tham khảo :http://net.devijfde.nl/2011/aggregator-date/   và http://api.drupal.org/api/drupal/modules--aggregator--aggregator.module/...

Cách 2 dùng PHP thuần : kích hoạt module PHP filter và viết code trong block

Thiết kế website - Code đọc tin rss bằng PHP

Code :

<?php

    $doc = new DOMDocument();

    $doc->load('<a href="http://vneconomy.vn/rss/chung-khoan'">http://vneconomy.vn/rss/chung-khoan'</a>);

<p>    $Feeds = array();

    $i = 0;</p>

<p>    foreach ($doc->getElementsByTagName('item') as $node){</p>

<p>        if($i == 5) break;</p>

<p>        $itemsRSS = array(

          'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,

          'link'  => $node->getElementsByTagName('link')->item(0)->nodeValue,

           'pubDate'  => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,

        );</p>

<p>        array_push($Feeds, $itemsRSS);

        ++$i;

    }

    echo '<ul>';

    foreach ($Feeds as $feed){

        echo '<li>';

        echo "<a href='{$feed['link']}'>".$feed['title'].'</a>';

        echo $feed['pubDate'].'';

        echo '</li>';

    }

    echo '</ul>';

?></p>
Bạn thấy bài viết này như thế nào?: 
No votes yet
Ảnh của Khanh Hoang

Khanh Hoang - Kenn

Kenn is a user experience designer and front end developer who enjoys creating beautiful and usable web and mobile experiences.

Bình luận (0)

 

Add Comment

Filtered HTML

  • Các địa chỉ web và email sẽ tự động được chuyển sang dạng liên kết.
  • Các thẻ HTML được chấp nhận: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Tự động ngắt dòng và đoạn văn.

Plain text

  • No HTML tags allowed.
  • Các địa chỉ web và email sẽ tự động được chuyển sang dạng liên kết.
  • Tự động ngắt dòng và đoạn văn.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
Google hay Facebook sẽ mua LinkedIn?

Google hay Facebook sẽ mua LinkedIn?

Sau khi thông báo doanh thu tăng hơn gấp đôi và lợi nhuận đạt 30% trong quý 4/2011, cổ phiếu của LinkedIn tăng gần 18%. Mạng xã hội nghề nghiệp này có sự hấp dẫn riêng.

Nâng cấp Drupal User Profiles với Profile2

Nâng cấp Drupal User Profiles với Profile2

Drupal 7 has made it easy for you to allow your site users to share information about themselves. User accounts are now "entities" which means that you can add fields to them, just as with content.

Command line khởi động MySQ L trên Red Hat Linux

Command line khởi động MySQ L trên Red Hat Linux

After you've installed MySQL it's often a good and convenient idea to make it start and stop automatically with the machine. These instructions are specific for Red Hat Linux and it's variants since different Linux distributions tend to layout the start up scripts differently.

Công ty diệt chuột T&C

 

Diet con trung