1
我想從我的WordPress博客創建一個完全自定義的提要,以便它可以被使用NewsML的內容管理系統攝取。 You can learn about NewsML and find a NewsML validator here。如何創建一個NewsML WordPress提要
我的方法是創建一個WP頁面模板,生成xml而不是HTML,由一個叫Yoast的人描述(google他,我不能發佈太多的鏈接b/c我是新來的)。但是,似乎沒有什麼能滿足NewsML驗證器。有沒有人對創建NewsML Feed和/或使用WordPress做任何體驗有任何見解?看起來,NewsML非常複雜,在我轉身的任何地方都會讓我絆倒。
這裏是我想出來創建Feed的模板。隨意嘗試一下,如果你想。
<?php
$numposts = 10;
function yoast_rss_date($timestamp = null) {
$timestamp = ($timestamp==null) ? time() : $timestamp;
echo date(DATE_RSS, $timestamp);
}
function yoast_rss_text_limit($string, $length, $replacer = '...') {
$string = strip_tags($string);
if(strlen($string) > $length)
return (preg_match('/^(.*)\W.*$/', substr($string, 0, $length+1), $matches) ? $matches[1] : substr($string, 0, $length)) . $replacer;
return $string;
}
$posts = query_posts('showposts='.$numposts);
$lastpost = $numposts - 1;
header("Content-Type: application/rss+xml; charset=UTF-8");
echo '<?xml version="1.0"?>';
?>
<NewsML>
<Catalog Href="http://www.iptc.org/std/catalog/catalog.IptcMasterCatalog.xml"/>
<NewsEnvelope>
<DateAndTime><?php echo mysql2date('Ymd', get_lastpostmodified('GMT'), false); ?>T<?php echo mysql2date('His', get_lastpostmodified('GMT'), false); ?></DateAndTime>
<NewsService FormalName="Thumbnail" link-url="http://example.com">
http://example.com/images/example.gif
</NewsService>
</NewsEnvelope>
<?php foreach ($posts as $post) { ?>
<?php setup_postdata($post); ?>
<NewsItem LinkType="normal">
<Identification>
<NewsIdentifier>
<ProviderId><?php the_author(); ?></ProviderId>
</NewsIdentifier>
</Identification>
<NewsManagement>
<NewsItemType FormalName="News"/>
<FirstCreated><?php the_time(Ymd); ?>T<?php the_time(His); ?></FirstCreated>
<ThisRevisionCreated><?php the_modified_time(Ymd); ?>T<?php the_modified_time(Ymd); ?></ThisRevisionCreated>
<Status FormalName="Usable"/>
</NewsManagement>
<NewsComponent Duid="<?php echo get_permalink($post->ID); ?>copyright" Essential="no" EquivalentsList="no">
<NewsLines>
<CopyrightLine>Placeholding</CopyrightLine>
</NewsLines>
<NewsComponent Duid="<?php echo get_permalink($post->ID); ?>">
<DateLine><?php the_time(Ymd); ?>T<?php the_time(His); ?></DateLine>
<Author><?php the_author(); ?></Author>
<NewsComponent>
<Role FormalName="Main"/>
<NewsLines>
<HeadLine><?php echo get_the_title($post->ID); ?></HeadLine>
<SlugLine>
<?php the_excerpt(); ?>
</SlugLine>
<MoreLink>
<?php echo get_permalink($post->ID); ?>
</MoreLink>
</NewsLines>
<ContentItem link-url="<?php echo get_permalink($post->ID); ?>">
<DataContent>
<nitf>
<body>
<body.head>
<hedline>
<hl1><?php echo get_the_title($post->ID); ?></hl1>
</hedline>
</body.head>
<body.content>
<?php echo apply_filters('the_content',$post->post_content); ?>
</body.content>
</body>
</nitf>
</DataContent>
</ContentItem>
</NewsComponent>
</NewsComponent>
</NewsComponent>
</NewsItem>
<?php } ?>
</NewsML>
太棒了。謝謝塔克!我們也一直在使用CDATA機箱。很高興聽到這對你有用! – 2011-03-24 15:03:24