We Can Add Any PHP Feed Aggregator Snippet in Our Example WordPress Dashboard Widget’s Source To Get WordPress Dashboard Widget Custom Feed. Where is that Example WordPress Dashboard Widget? The Example WordPress Dashboard Widget is here. Actually with that same thing, we iframed Google Trends Graph. It will not interfere the default functions of other widgets.
WordPress Dashboard Widget Custom Feed : The PHP Snippet For Fetching Feed
There are many ready to use libraries to fetch feed. SimplePie is well known, it very easy to use Free Software and easy-to-use feed parser. This is an easy snippet to fetch feed :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <?php $rss = new DOMDocument(); $rss->load('https://thecustomizewindows.com/feed/'); $feed = array(); foreach ($rss->getElementsByTagName('item') as $node) { $item = array ( 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue, 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue, 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, 'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue, ); array_push($feed, $item); } $limit = 5; for($x=0;$x<$limit;$x++) { $title = str_replace(' & ', ' & ', $feed[$x]['title']); $link = $feed[$x]['link']; $description = $feed[$x]['desc']; $date = date('l F d, Y', strtotime($feed[$x]['date'])); echo '<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />'; echo '<small><em>Posted on '.$date.'</em></small></p>'; echo '<p>'.$description.'</p>'; } ?> |
The URL in the line $rss->load('https://thecustomizewindows.com/feed/');
should be changed to own intended URL. You will get the same file on GitHub repo. Copy Paste from there in any Text Editor.
---
There are more advanced Feed Fetchers, this is a basic example to get WordPress Dashboard Widget Custom Feed.
WordPress Dashboard Widget Custom Feed : Making it Working With Example Dashboard Widget
You need to install that Example Dashboard Widget. Read the article carefully and install it or modify and install it. We are taking that you have already installed it, so you will modify directly on WordPress Plugin Editor. Actually we can directly do it from WordPress using the WordPress Plugin Editor, URL will be like this :
1 | example_dashboard_widget/widget.php |
From the dropdown, select Example Dashboard Widget if you are using our default WordPress plugin. If you have changed the name, that will be the name. Click the select button. The file which you™ll edit is :
1 | example_dashboard_widget/widget.php |
Just simple editing of a plugin file. You’ll remove everything including these lines and add the PHP Feed Generator snippet :
1 2 3 4 5 6 | <?php /** * This file could be used to catch submitted form data. When using a non-configuration * view to save form data, remember to use some kind of identifying field in your form. */ ?> |
PHP ending and closing not required as we have it on our Feed Snippet, So the widget.php
file is becoming like :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <?php $rss = new DOMDocument(); $rss->load('https://thecustomizewindows.com/feed/'); $feed = array(); foreach ($rss->getElementsByTagName('item') as $node) { $item = array ( 'title' => $node->getElementsByTagName('title')->item(0)->nodeValue, 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue, 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, 'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue, ); array_push($feed, $item); } $limit = 5; for($x=0;$x<$limit;$x++) { $title = str_replace(' & ', ' & ', $feed[$x]['title']); $link = $feed[$x]['link']; $description = $feed[$x]['desc']; $date = date('l F d, Y', strtotime($feed[$x]['date'])); echo '<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />'; echo '<small><em>Posted on '.$date.'</em></small></p>'; echo '<p>'.$description.'</p>'; } ?> |