السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ

KuyLa Blog - Welcome back in this blog yg acak-acakan :v di postingan kali ini saya akan kasih source code untuk membuat RSS pada UBlog. Langsung aja, sebelumnya kalian harus pake script UBlog terlebih dahulu, jika sudah kuy!!!

1. Buat sebuah file di folder public_html, atau htdocs, beri nama rss.php
2. Ketik code seperti dibawah ini!

<?php

	require('database.php');
	$config = $pdo->query("
		SELECT *
		FROM blog_setting
	")->fetch(PDO::FETCH_OBJ);

	header('Content-Type: text/xml; charset=utf-8'.true);

	$rss = new SimpleXMLElement('<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom"></rss>');
	$rss->addAttribute('version', '2.0');

	$channel = $rss->addChild('channel');

	$atom = $rss->addChild('atom:atom:link');
	$atom->addAttribute('href', $config->url);
	$atom->addAttribute('rel', 'self');
	$atom->addAttribute('type', 'application/rss+xml');

	$title = $rss->addChild('title', $config->title);
	$description = $rss->addChild('description', $config->description);
	$link = $rss->addChild('link', $config->url);
	$language = $rss->addChild('language', 'en-us');

	$date_f = date('D, d M Y H:i:s T', time());
	$build_date = gmdate(DATE_RFC2822, strtotime($date_f));
	$lastBuildDate = $rss->addChild('lastBuildDate', $date_f);

	$generator = $rss->addChild('generator', 'PHP Simple XML');

	$result = $pdo->query("
		SELECT *
		FROM blog_post
		WHERE status = 1
		ORDER BY upat
	");

	if ($result) {
		while ($row = $result->fetch(PDO::FETCH_OBJ)) {
			$item = $rss->addChild('item');
			$title = $item->addChild('title', $row->title);
			$link = $item->addChild('guid', $config->url.'/post/'.$row->permalink.'.html');

			$guid = $item->addChild('guid', $config->url.'/post/'.$row->permalink.'.html');
			$guid->addAttribute('isPermalink', 'false');

			$description = $item->addChild('description', htmlspecialchars(substr(trim(strip_tags($row->text)), 0, 321)).' <b><a href="'.$config->url.'/post/'.$row->permalink.'.html">Read More</a></b>');

			$date_rfc = gmdate(DATE_RFC2822, strtotime($row->time));
			$item = $item->addChild('pubDate', $date_rfc);
		}
	}

	echo $rss->asXML();
3. Save

Nah simple kan, silahkan pelajari sendiri codenya, karena waktu saya sangat rumit :v silahkan repost jika perlu, tapi jangan lupa cantumin sumber, source code ini dibuat oleh saya dan beberapa bantuan dari mbah google :D Thanks, and Wait for the next post.

وَ السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُهُ