Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE REQUEST]How to integrate into root domain? #783

Open
vvcares opened this issue Jul 13, 2024 · 2 comments
Open

[FEATURE REQUEST]How to integrate into root domain? #783

vvcares opened this issue Jul 13, 2024 · 2 comments

Comments

@vvcares
Copy link

vvcares commented Jul 13, 2024

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..

@danpros
Copy link
Owner

danpros commented Jul 13, 2024

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).

@KuJoe
Copy link
Contributor

KuJoe commented Aug 15, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants