Showing posts with label Get posts using wordpress rss feed url and add featured post thumbnails in WordPress feeds. Show all posts
Showing posts with label Get posts using wordpress rss feed url and add featured post thumbnails in WordPress feeds. Show all posts

Wednesday 19 July 2017

Get posts using wordpress rss feed url and add featured post thumbnails in WordPress feeds

Get posts using wordpress rss feed url and add featured post thumbnails in WordPress feeds


Hello

here the example of geting data from rss feed url

this code in your current wordpress function.php file 
// display featured post thumbnails in WordPress feeds
function wcs_post_thumbnails_in_feeds( $content ) {
    global $post;
    if( has_post_thumbnail( $post->ID ) ) {
        $content = '<p>' . get_the_post_thumbnail( $post->ID ) . '</p>' . $content;
    }
    return $content;
}
add_filter( 'the_excerpt_rss', 'wcs_post_thumbnails_in_feeds' );
add_filter( 'the_content_feed', 'wcs_post_thumbnails_in_feeds' );

$url = 'Your Wordpress Rss Fedd';

    $rss = new DOMDocument();
    $rss->load($url);
    $feed = array();
    foreach ($rss->getElementsByTagName('item') as $node) {
        $item = array (
                'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
                'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
                'pubDate' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
                'description' => $node->getElementsByTagName('description')->item(0)->nodeValue,
                'content' => $node->getElementsByTagName('encoded')->item(0)->nodeValue

                );
       array_push($feed, $item);
    }



  
  
 
foreach($feed as $f){
preg_match('/<img.+src=[\'"](?P<src>.+?)[\'"].*>/i', $f['description'], $image);

   $content = strip_tags(preg_replace("/<img[^>]+\>/i", "", $image[0]),"</p>");
  
$pos = strrpos( $content, '[');
echo  $image['src']; // Get Feature image in rss
echo $f['link']; // Get Link in post
echo $f['title']; // get Title of post
echo $f['pubDate']; // get Publish date
echo rtrim (substr($content, 0, $pos) ); // Only get description


}