htmly
htmly copied to clipboard
[FEATURE REQUEST]How to integrate into root domain?
My HTMLy blog is inside my root/blog. I wish to get the my blog's LATEST POSTS INDEX into my root domain's page. How to integrate please?
Is something like same as wordpress latest posts widget..
I don't know what CMS is used on the root domain, but for example if it is WP then you can use a plugin to read the RSS feed on the blog.
If the root domain uses, for example, a static page, use PHP to read the RSS feed (eg. using SimpleXmlElement).
Something like this should work:
<?php
// Replace with the actual RSS feed URL
$feed_url = "https://example.com/blog/feed/rss";
// Fetch the feed content
$feed_content = file_get_contents($feed_url);
// Check if content was fetched successfully
if ($feed_content) {
// Parse the XML content
$xml = simplexml_load_string($feed_content);
// Get the first item (latest post)
$latest_post = $xml->channel->item[0];
// Extract title and link
$title = $latest_post->title;
$link = $latest_post->link;
$text = $latest_post->description;
$cat = $latest_post->category;
$date_string = $latest_post->pubDate;
$date = new DateTime($date_string);
// Display the information
echo $title.'<br />';
echo $text." <a href='$link'>[Read More]</a><br />";
echo "Posted $date in $cat";
} else {
echo "Error: Could not retrieve blog contents.";
}
?>
If you need to display more than one post, you can loop the code and change item[0] to increment.