更新日時と実際の日付
Blogで日記サイトをやっていると、その日に書かないと実際の日付と投稿日時がずれるので今ひとつ。
うちのサイトもたいてい次の日の朝更新されるので、日付は1日ずれてしまいます。
ある程度は記事に「最終更新:」というものを出力して、それで代用してるんですけどね。
さて、Google Sitemapsに登録する場合、最終更新日時を書くことができるのですが、それが記事の日付だとちと具合が悪かったり。
というわけで、うちで「最終更新:」を表示しているプラグイン、NP_UpdateTimeを改造しました。
Google sitemaps用のXmlファイルの中では、<lastmod>にて更新日時を登録できます。
Google Sitemapなら…これをベースにされるといいんじゃないでしょうか?
hsurさんのGoogle Sitemaps 対応 Nucleus Skin
http://blog.cles.jp/item/889
Nucleus日本語フォーラムで紹介いただいたこちらのサイトでは、Nucleusの<%date()%>テンプレート変数で出力されますが、私のサイトではアイテムの日時=更新日でないことも多いので、NP_UpdateTimeでlastmodを出力できるように改造します。
<%UpdateTime%>と<%date%>の使い分け方法
http://japan.nucleuscms.org/bb/viewtopic.php?t=893
こちらのNucleus日本語フォーラムのjunさんの記事を参考に、<%date%>のitemの時間と<%UpdateTime%>の更新日時を比較し、新しいほうの時間を指定したフォーマットで出力させます。
NP_UpdateTimeの107行付近、doTemplateVar(&$item)を以下のコードに置き換えます。
function doTemplateVar(&$item,$forMaps){
if($forMaps == ''){
$query = 'SELECT r.up_id, UNIX_TIMESTAMP(r.updatetime) as updatetime, UNIX_TIMESTAMP(i.itime) as itemtime FROM '.sql_table('plugin_rectime') . ' as r, '.sql_table('item') .' as i WHERE r.up_id='.$item->itemid.' and r.up_id=i.inumber';
$res = sql_query($query);
if($row = mysql_fetch_assoc($res)){
$data['utime'] = date($this->getOption('DateFormat'),$row['updatetime']);
if($row['updatetime'] > $row['itemtime']){
echo TEMPLATE::fill($this->getOption('AfterTime'),$data);;
}elseif($row['updatetime'] < $row['itemtime']){
echo TEMPLATE::fill($this->getOption('BeforeTime'),$data);;
}
}
}else{ // add
$query = 'SELECT r.up_id, UNIX_TIMESTAMP(r.updatetime) as updatetime, UNIX_TIMESTAMP(i.itime) as itemtime, i.inumber FROM '.sql_table('item') . ' as i left join '.sql_table('plugin_rectime') .' as r on r.up_id=i.inumber WHERE i.inumber='.$item->itemid;
$res = sql_query($query);
if($row = mysql_fetch_assoc($res)){
$data['utime'] = date($this->getOption('DateFormat'),$row['updatetime']);
$up_id = quickQuery('SELECT up_id as result FROM '.sql_table('plugin_rectime').' WHERE up_id = '.$row['inumber']);
if(!$up_id){
echo formatDate($forMaps, $row['itemtime'],$this->getOption('DateFormat'));
} elseif($row['updatetime'] > $row['itemtime']){
echo formatDate($forMaps, $row['updatetime'],$this->getOption('DateFormat'));
} else {
echo formatDate($forMaps, $row['itemtime'],$this->getOption('DateFormat'));
}
}
} // add end
}
この変更後、テンプレートに
<lastmod><%UpdateTime(utc)%></lastmod>
のように表記すると、更新日時がUTCフォーマットで出力されます。
指定可能なフォーマットは、rfc822,rfc822GMT,utc,iso8601です。
通常のNP_UpdateTimeの出力を行う場合には、これまでどおり<%UpdateTime%>と表記すればよいです。
最終更新:06/06/11 10:29
キーワードを含む記事(サイト内)
keyword:[更新日時]
コメント
コメントの追加
トラックバック
このエントリにトラックバックはありません
着々と・・・