This repository was archived by the owner on Jan 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Add RSS feed function #6
Copy link
Copy link
Open
Description
I don't know if everyone needs this so I didn't use the commit branch but submitted it here.
If you need this function, please copy the code and create a new rss.php file in the / root directory and paste the following code (url/rss.php).
<?php header("Content-Type: application/xml");
echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
<rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
>
<channel>
<title>Daniel's Blog</title>
<link><strong>https://petabyt.dev/blog/</strong></link>
<description>Astronomy enthusiasts</description>
<language>en-US</language>
<sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>1</sy:updateFrequency>
<generator>https://petabyt.dev/blog/</generator>
<?php
# Automatically count files in /posts
$postsDirectory = scandir("posts");
$postCount = count($postsDirectory) - 2;
$page=isset($_GET["page"])?$_GET["page"]:0;
$max=8; //Set the number of RSS posts to be displayed
for ($post = $postCount; $post >= 1; $post--) {
$txt=file("posts/" . strval($post));
$txt[0]=$txt[0] ."@";
$txt[1]=$txt[1] ."@";
$txt[2]=$txt[2] . "" . @$txt[3] . "" .@$txt[4] ."@";
$txt[3]=strval($post);
$array[]= $txt[0]. "" .$txt[1]. "" .$txt[2]. "" .$txt[3];
}
$i=count($array); //get array array Number of all article descriptions Paging
for ($j=$max*$page;$j<($max*$page+$max)&&$j<$i;++$j) { //Cyclic conditions control the number of images displayed
$post = explode('@', $array[$j]); // Splitting an array @ before depositing it for easy reading
//.$post[0]. Title .$post[3]. URL-id .$post[1]. date .$post[3]. Description
$content = <<<HTML
<item>
<title>$post[0]</title>
<link>https://petabyt.dev/blog/?post=$post[3]</link>
<guid>https://petabyt.dev/blog/?post=$post[3]</guid>
<dc:creator>Daniel</dc:creator>
<pubDate>$post[1]</pubDate>
<description><![CDATA[$post[2]]]></description>
<content:encoded><![CDATA[$post[2]]]></content:encoded>
</item>
HTML;
echo $content;
}
?>
</channel>
</rss>Additional.
You can use apache or nginx to rewrite this address to make it more aesthetically pleasing and seo-compatible.
nginx:
rewrite ^/feed.xml$ /rss.php last;
apache:
RewriteRule ^feed.xml$ rss.php [L]
petabyt
Metadata
Metadata
Assignees
Labels
No labels
