Topツール > Feed2JS の表示結果のタイトルに日付を表示する
2009年6月16日

Feed2JS の表示結果のタイトルに日付を表示する

Posted at June 16,2009 1:55 AM
Category:[ツール]
Tag:[, , , , , , ]

フィードの内容をブログ等に表示するツール「Feed2JS」を使ったときに、タイトル横に日付を表示する方法です。

Feed2JS の詳細については、「RSS Feed(フィード)を表示する」をご覧ください。

下の例は、はてなブックマーク「最近の人気エントリー」のフィードを表示した場合の、変更前と変更後です。変更前はタイトル下に日付と時刻が表示されますが、変更後はタイトルの左に日付を表示します(いずれも設定項目の「Show item posting date? 」を「Yes」に設定)。

変更前
変更前

変更後
変更後

西暦を2桁表示することも可能です。
西暦を2桁表示

元のように、時刻も表示できます。
時刻も表示

1.タイトル横に日付を適用する

自サーバにアップロードした feed2js ディレクトリ直下にある、feed2js.php の 200 行目あたり(確認バージョンは1.98)にある、下記の赤色部分を削除し、青色部分を追加します。バージョンによって行が異なる場合は似たような箇所をみつけてください。

変更前(赤色を削除)

...前略...
if ($desc < 0) {
    $str.= "document.write('<li class=\"rss-item\">');\n";
    
} elseif ($item['title']) {
    // format item title
    $my_title = addslashes(strip_returns($item['title']));
                
    // create a title attribute. thanks Seb!
    $title_str = substr(addslashes(strip_returns(strip_tags((htmlspecialchars($item['summary']))))), 0, 255) . '...'; 
 
    // write the title strng
    $str.= "document.write('<li class=\"rss-item\"><a class=\"rss-item\" href=\"" . trim($my_url) . "\" title=\"$title_str\"". $target_window . '>' . $my_title . "</a><br />');\n";
 
} else {
    // if no title, build a link to tag on the description
    $str.= "document.write('<li class=\"rss-item\">');\n";
    $more_link = " <a class=\"rss-item\" href=\"" . trim($my_url) . '"' . $target_window . ">&laquo;details&raquo;</a>";
}
 
// print out date if option indicated
 
if ($date == 'y') {
            
    if ($tz == 'feed') {
    //   echo the date/time stamp reported in the feed
 
        if ($item['pubdate'] != '') {
            // RSS 2.0 is alreayd formatted, so just use it
            $pretty_date = $item['pubdate'];
        } elseif ($item['published'] != "") {
            // ATOM 1.0 format, remove the "T" and "Z" and the time zone offset
            $pretty_date = str_replace("T", " ", $item['published']);
            $pretty_date= str_replace("Z", " ", $pretty_date);
 
        } elseif ($item['issued'] != "") {
            // ATOM 0.3 format, remove the "T" and "Z" and the time zone offset
            $pretty_date = str_replace("T", " ", $item['issued']);
            $pretty_date= str_replace("Z", " ", $pretty_date);
        } elseif ( $item['dc']['date'] != "") {
            // RSS 1.0, remove the "T" and the time zone offset
            $pretty_date = str_replace("T", " ", $item['dc']['date']);
            $pretty_date = substr($pretty_date, 0,-6);
        } else {
        
            // no time/date stamp, 
            $pretty_date =  'n/a';
        }
 
    } else {
        // convert to local time via conversion to GMT + offset
        
        // adjust local server time to GMT and then adjust time according to user
        // entered offset.
        
        $pretty_date = date($date_format, $item['date_timestamp'] - $tz_offset + $tz * 3600);
    
    }
 
    $str.= "document.write('<span class=\"rss-date\">$pretty_date</span><br />');\n"; 
}
 
// link to podcast media if availavle
...後略...

変更後(青色を追加)

...前略...
if ($desc < 0) {
    $str.= "document.write('<li class=\"rss-item\">');\n";
    
} elseif ($item['title']) {
    // format item title
    $my_title = addslashes(strip_returns($item['title']));
                
    // create a title attribute. thanks Seb!
    $title_str = substr(addslashes(strip_returns(strip_tags((htmlspecialchars($item['summary']))))), 0, 255) . '...'; 
 
    // print out date if option indicated
 
    if ($date == 'y') {
            
        if ($tz == 'feed') {
        //   echo the date/time stamp reported in the feed
 
            if ($item['pubdate'] != '') {
                // RSS 2.0 is alreayd formatted, so just use it
                $pretty_date = $item['pubdate'];
            } elseif ($item['published'] != "") {
                // ATOM 1.0 format, remove the "T" and "Z" and the time zone offset
                $pretty_date = str_replace("T", " ", $item['published']);
                $pretty_date= str_replace("Z", " ", $pretty_date);
 
            } elseif ($item['issued'] != "") {
                // ATOM 0.3 format, remove the "T" and "Z" and the time zone offset
                $pretty_date = str_replace("T", " ", $item['issued']);
                $pretty_date= str_replace("Z", " ", $pretty_date);
            } elseif ( $item['dc']['date'] != "") {
                // RSS 1.0, remove the "T" and the time zone offset
                $pretty_date = str_replace("T", " ", $item['dc']['date']);
                $pretty_date = substr($pretty_date, 0,-6);
            } else {
        
                // no time/date stamp, 
                $pretty_date =  'n/a';
            }
 
        } else {
            // convert to local time via conversion to GMT + offset
        
            // adjust local server time to GMT and then adjust time according to user
            // entered offset.
        
            $pretty_date = date($date_format, $item['date_timestamp'] - $tz_offset + $tz * 3600);
    
        }
        $pretty_date = substr($pretty_date, 0,-8);
    }
 
    // write the title strng
    $str.= "document.write('<li class=\"rss-item\">$pretty_date <a class=\"rss-item\" href=\"" . trim($my_url) . "\" title=\"$title_str\"". $target_window . '>' . $my_title . "</a><br />');\n";
 
} else {
    // if no title, build a link to tag on the description
    $str.= "document.write('<li class=\"rss-item\">');\n";
    $more_link = " <a class=\"rss-item\" href=\"" . trim($my_url) . '"' . $target_window . ">&laquo;details&raquo;</a>";
}
 
// link to podcast media if availavle
...後略...

2.西暦を2桁にする

表示されている西暦を4桁から2桁にするには、1項で追加した、

$pretty_date = substr($pretty_date, 0,-8);

$pretty_date = substr($pretty_date, 2,-8);

に変更します。

3.時刻を表示する

時刻を表示するには、1項で追加した、

$pretty_date = substr($pretty_date, 0,-8);

の1行を丸ごと削除してください。

Posted by yujiro   このページの先頭に戻る
関連記事
この記事を読んだ人はこんな記事も読んでいます
人気エントリー
Hatena Hot Entries
Hatena Entries
トラックバックURL


コメント

はじめまして。

小枠空間様のFeed2JSを使用させていただいてます。

このFeed2JSを使って、新着の記事が分かるように「New!」マークみたいなものを表示させたいと思っています。

具体的には、

・10/12/09  今日もいい天気でした! [New!]

みたいな感じです。

ソースを見てみたのですが、ソースを見てもどこをどういじくったらいいのか分からず困っています。

どうすれば新着マークを表示できるようにできるでしょうか?

※phpが使えるサーバにアップしています。

[1] Posted by ブログ初心者 : January 9, 2010 10:25 PM

いつもお世話になっています。出版物共に解りやすくて助かります。

恐れ入ります。古いエントリーであり、Feed2JSの事なので、見て頂けるか心配ですが、お力になって頂ければ幸いです。

表示を2010年02月21日とするには、どのようにしたら宜しいでしょうか?よろしくお願い致します。

[2] Posted by fra : February 21, 2010 11:36 PM
コメントする
greeting

*必須

*必須(非表示)


ご質問のコメントの回答については、内容あるいは多忙の場合、1週間以上かかる場合があります。また、すべてのご質問にはお答えできない可能性があります。予めご了承ください。

太字 イタリック アンダーライン ハイパーリンク 引用
[サインインしない場合はここにCAPTCHAを表示します]

コメント投稿後にScript Errorや500エラーが表示された場合は、すぐに再送信せず、ブラウザの「戻る」ボタンで一旦エントリーのページに戻り(プレビュー画面で投稿した場合は、投稿内容をマウスコピーしてからエントリーのページに戻り)、ブラウザをリロードして投稿コメントが反映されていることを確認してください。

コメント欄に(X)HTMLタグやMTタグを記述される場合、「<」は「&lt;」、「>」は「&gt;」と入力してください。例えば「<$MTBlogURL$>」は「&lt;$MTBlogURL$&gt;」となります(全て半角文字)

Now loading...
Introduction
Entries of this Category
Recent Entries
Recent Comments
Recent Trackbacks
QRcode

現在停止中です
携帯電話からこのQRcodeを撮影することで携帯用URLを取得することができます

URI for cellular phones
ギターに入った猫
Styles
Font Size
Default
For defective color vision
Gray Scale
RGB Color
Search this site

このブログをメールで購読する by:FeedBurner

loading ...
Categories
Monthly Archives
BlogPeople
Syndicate this site
FeedBurner(RSS1.0/RSS2.0/Atom)
Counter
これまでのアクセス
クリエイティブ・コモンズ・ライセンス
Powered by
Movable Type 5.12