Skip to content

Instantly share code, notes, and snippets.

@iansoper
Created December 30, 2010 18:49
Show Gist options
  • Save iansoper/760116 to your computer and use it in GitHub Desktop.
Save iansoper/760116 to your computer and use it in GitHub Desktop.
<?php
$numposts = 2;
function rss_date( $timestamp = null ) {
$timestamp = ($timestamp==null) ? time() : $timestamp;
echo date(DATE_RSS, $timestamp);
}
function 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;
}
//Create a new filtering function that will add our where clause to the query
function filter_where($where = '') {
//posts in the last 1 days
$where .= " AND post_date > '" . date('Y-m-d', strtotime('-1 days')) . "'";
return $where;
}
// Register the filtering function
add_filter('posts_where', 'filter_where');
// Perform the query, the filter will be applied automatically
$posts = query_posts('showposts='.$numposts);
$lastpost = $numposts - 1;
header("Content-Type: application/rss+xml; charset=UTF-8").'<?xml version="1.0"?>';
?><rss version="2.0">
<channel>
<title>CommonPrayer.net RSS Feed</title>
<link>http://commonprayer.net/</link>
<description>The Latest Daily Prayers from CommonPrayer.net</description>
<language>en-us</language>
<pubDate><?php strtotime($ps[$lastpost]->post_date_gmt); ?></pubDate>
<lastBuildDate><?php strtotime($ps[$lastpost]->post_date_gmt); ?></lastBuildDate>
<managingEditor>info@commonprayer.net</managingEditor>
<?php foreach ($posts as $post) { ?>
<?php //if ( have_posts() ) : while ( have_posts() ) : ?>
<?php //the_post(); ?>
<item>
<title><?php echo get_the_title($post->ID); ?></title>
<link><?php echo get_permalink($post->ID); ?></link>
<description><?php //echo '<![CDATA['.rss_text_limit($post->post_content, 500).'<br/><br/>Keep on reading: <a href="'.get_permalink($post->ID).'">'.get_the_title($post->ID).'</a>'.']]>'; ?>
<?php the_content() ?>
</description>
<pubDate><?php rss_date( strtotime($post->post_date_gmt) ); ?></pubDate>
<guid><?php echo get_permalink($post->ID); ?></guid>
</item>
<?php// endwhile; ?>
<?php// else: ?>
<?php //endif; ?>
<?php } ?>
</channel>
</rss>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment