tp090

custom-feed.php

Apr 8th, 2017
27
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3. Template Name: Custom Feed
  4. */
  5.  
  6. $numposts = 5;
  7.  
  8. function yoast_rss_date( $timestamp = null ) {
  9.   $timestamp = ($timestamp==null) ? time() : $timestamp;
  10.   echo date(DATE_RSS, $timestamp);
  11. }
  12. /*
  13. function yoast_rss_text_limit($string, $length, $replacer = '...') {
  14.   $string = strip_tags($string);
  15.   if(strlen($string) > $length)
  16.     return (preg_match('/^(.*)\W.*$/', substr($string, 0, $length+1), $matches) ? $matches[1] : substr($string, 0, $length)) . $replacer;
  17.   return $string;
  18. }
  19. */
  20. $posts = query_posts('showposts='.$numposts);
  21.  
  22. $lastpost = $numposts - 1;
  23.  
  24. header("Content-Type: application/rss+xml; charset=UTF-8");
  25. echo '<?xml version="1.0"?>';
  26. ?><rss version="2.0">
  27. <channel>
  28.   <title>Flashfictionmagazine</title>
  29.   <link>https://flashfictionmagazine.com/</link>
  30.   <description>The latest blog posts from Flashfictionmagazine.com</description>
  31.   <language>en-us</language>
  32.   <pubDate><?php yoast_rss_date( strtotime($ps[$lastpost]->post_date_gmt) ); ?></pubDate>
  33.   <lastBuildDate><?php yoast_rss_date( strtotime($ps[$lastpost]->post_date_gmt) ); ?></lastBuildDate>
  34.   <managingEditor>joost@yoast.com</managingEditor>
  35. <?php foreach ($posts as $post) {
  36. ?>
  37.   <item>
  38.     <title><?php echo get_the_title($post->ID); ?></title>
  39.     <link><?php echo get_permalink($post->ID); ?></link>
  40. <description><?php echo '<![CDATA['.'<p><span>by </span><strong>'.get_post_meta($post->ID,'pen_name',true).'</strong></p>'.the_excerpt_rss().'<br/><a href="'.get_permalink($post->ID).'">Read the rest</a>'.']]>';  ?></description>
  41.     <guid><?php echo get_permalink($post->ID); ?></guid>
  42.   </item>
  43. <?php } ?>
  44. </channel>
  45. </rss>
RAW Paste Data