2009年10月26日月曜日

ブログをTOPページのニュースに表示

ウェブサイトのトップにブログをニュースのように貼りつける。phpが使えるサイトじゃないとダメなんですが。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// movable type
<?php
$xml = simplexml_load_file("http://www.hogehoge.jp/rss.xml");
 
$cnt=3; //表示件数
 
foreach ( $xml->channel->item as $item) {
 
    $url = $item->link;
    $wtime = date("Y/m/d H:i:s",strtotime($item->pubDate));
    echo '<h3><a href="'.$url.'">'.$item->title."</a></h3>";
    echo '<div id="blogtime"><h4>'.$wtime.'</h4></div>';
    echo '<div id="blogkiji"><p>'.$item->description.'</p></div>';
    echo '
';
    $cnt--;
 
    if($cnt<=0){
        break;
    }
 
}
?>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// wordpress ブログ
<?php
$xml = simplexml_load_file("http://weblog.hogehoge.com/feed");
$cnt=3; //表示件数
 
foreach ( $xml->channel->item as $item) {
 
    if(strstr($item->title,"[PR]")){
    }else{
        $url = $item->link;
        $wtime = date("Y/m/d H:i:s",strtotime($item->pubDate));
        echo '<h3><a href="'.$url.'">'.$item->title."</a></h3>";
        echo '<div id="blogtime"><h4>'.$wtime.'</h4></div>';
        echo '<div id="blogkiji"><p>'.$item->description.'</p></div>';
        echo '
';
        $cnt--;
    }
 
    if($cnt<=0){
        break;
    }
 
}
?>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// seesaa ブログ,
// eshizuoka ブログは "http://hogehoge.eshizuoka.jp/index.xml"
<?php
$xml = simplexml_load_file("http://hogehoge.com/index20.rdf");
$cnt=3; //表示件数
 
foreach ( $xml->channel->item as $item) {
 
    if(strstr($item->title,"[PR]")){
    }else{
        $url = $item->link;
        $wtime = date("Y/m/d H:i:s",strtotime($item->pubDate));
        echo '<h3><a href="'.$url.'">'.$item->title."</a></h3>";
        echo '<div id="blogtime"><h4>'.$wtime.'</h4></div>';
        echo '<div id="blogkiji"><p>'.$item->description.'</p></div>';
        echo '
';
        $cnt--;
    }
 
    if($cnt<=0){
        break;
    }
 
}
?>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// JUGEM ブログ
<?php
$xml = simplexml_load_file("http://hogehoge.jp/atom.xml");
//print_r($xml);
$cnt=3; //表示件数
//foreach ( $xml->channel->item as $item) {
foreach ( $xml->entry as $item) {
 
    if(strstr($item->title,"[PR]")){
    }else{
        $url = $item->id;
        $wtime = date("Y/m/d H:i:s",strtotime($item->issued));
        echo '<h3><a href="'.$url.'">'.$item->title."</a></h3>";
        echo '<div id="blogtime"><h4>'.$wtime.'</h4></div>';
        echo '<div id="blogkiji"><p>'.$item->summary.'</p></div>';
        echo '
';
        $cnt--;
    }
 
    if($cnt<=0){
        break;
    }
 
}
?>