I have set up a blog on a subdomain. like blog.mywebsite.com
And I have set up a recent posts widget using RSS Feed on my main website’s homepage.
I have managed to display the most recent 3 posts in that widget.
But now when I add a new post on the subdomain blog site that widget is not getting updated. It is showing only old posts.
I used this tutorial to set up the widget. https://www.worldoweb.co.uk/2012/display-wordpress-posts-on-another-wp-blog
The actual PHP Code I am using on my website is below.
<?php
//replace with your URL
$rss = fetch_feed('https://blog.mywebsite.com/feed/');
if (!is_wp_error($rss)) :
$maxitems = $rss -> get_item_quantity(3); //gets latest 3 items This can be changed to suit your requirements
$rss_items = $rss -> get_items(0, $maxitems);
endif;
?>
<?php
//shortens description
function shorten($string, $length) {
$suffix = '…';
$short_desc = trim(str_replace(array("r", "n", "t"), ' ', strip_tags($string)));
$desc = trim(substr($short_desc, 0, $length));
$lastchar = substr($desc, -1, 1);
if ($lastchar == '.' || $lastchar == '!' || $lastchar == '?')
$suffix = '';
$desc .= $suffix;
return $desc;
}
?>
<!--start of displaying our feeds-->
<ul class="rss-items" id="wow-feed">
<?php
if ($maxitems == 0) echo '<li>No items.</li>';
else foreach ( $rss_items as $item ) :
?>
<li class="item">
<span class="data">
<h3><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></h3>
<span class="date-image"> </span>
<div class="rtin-date"><?php echo $item -> get_date('F j, Y'); ?></div>
<p class="rtin-content"><?php echo shorten($item -> get_description(), '120'); ?></p>
</span>
</li>
<?php endforeach; ?>
</ul>
What I want to do is.
when i add new post to my blog it should show in that RSS widget too.