Posted By

robnilas on 01/21/17


Tagged


Versions (?)

RSS Feed show on other blog


 / Published in: PHP
 

  1. <?php
  2. //add post thumbnails to RSS images
  3. function cwc_rss_post_thumbnail($content) {
  4. global $post;
  5. if(has_post_thumbnail($post->ID)) {
  6. $content = '<p>' . get_the_post_thumbnail($post->ID) .
  7. '</p>' . get_the_excerpt();
  8. }
  9.  
  10. return $content;
  11. }
  12. add_filter('the_excerpt_rss', 'cwc_rss_post_thumbnail');
  13. add_filter('the_content_feed', 'cwc_rss_post_thumbnail');
  14. ?>
  15.  
  16.  
  17. <?php
  18. $rss = fetch_feed('http://www.worldoweb.co.uk/feed');
  19.  
  20.  
  21. if (!is_wp_error( $rss ) ) :
  22.  
  23. $maxitems = $rss->get_item_quantity(5);
  24. $rss_items = $rss->get_items(0, $maxitems);
  25. endif;
  26. ?>
  27. <?php function get_first_image_url($html)
  28. {
  29. if (preg_match('/<img.+?src="(.+?)"/', $html, $matches)) {
  30. return $matches[1];
  31. }
  32. }
  33. ?>
  34. <?php
  35. function shorten($string, $length)
  36. {
  37. $suffix = '&hellip;';
  38. $short_desc = trim(str_replace(array("r","n", "t"), ' ', strip_tags($string)));
  39. $desc = trim(substr($short_desc, 0, $length));
  40. $lastchar = substr($desc, -1, 1);
  41. if ($lastchar == '.' || $lastchar == '!' || $lastchar == '?') $suffix='';
  42. $desc .= $suffix;
  43. return $desc;
  44. }
  45. ?>
  46. <ul class="rss-items" id="wow-feed">
  47. <?php
  48. if ($maxitems == 0) echo '<li>No items.</li>';
  49. else
  50. foreach ( $rss_items as $item ) : ?>
  51. <li class="item">
  52. <span class="rss-image">
  53. <?php echo '<img src="' .get_first_image_url($item->get_content()). '"/>'; ?>
  54. </span>
  55. <span class="data">
  56. <h5><a href='<?php echo esc_url( $item->get_permalink() ); ?>' title='<?php echo esc_html( $item->get_title() ); ?>'> <?php echo esc_html( $item->get_title() ); ?></a></h5>
  57. <span class="date-image">&nbsp;</span><small><?php echo $item->get_date('F Y'); ?> </small>
  58. <span class="comment-image">&nbsp;</span><small><?php $comments = $item->get_item_tags('http://purl.org/rss/1.0/modules/slash/', 'comments');?><?php $number = $comments[0]['data']; ?>
  59. <?php if ($number == '1'){ echo $number."&nbsp;". "Comment"; } else {echo $number. "&nbsp;"."Comments";}?></small>
  60. <p><?php echo shorten($item-> get_description(),'150');?></p>
  61. </span>
  62. </li>
  63. <?php endforeach; ?>
  64. </ul>

Report this snippet  

You need to login to post a comment.