PHP code example of bnomei / kirby3-feed

1. Go to this page and download the library: Download bnomei/kirby3-feed library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bnomei / kirby3-feed example snippets



$options = [
    'title'       => 'Latest articles',
    'description' => 'Read the latest news about our company',
    'link'        => 'blog'
];
echo page('blog')->children()->listed()->flip()->limit(10)->feed($options);

[
    'url' => site()->url(),
    'feedurl' => site()->url() . '/feed/',
    'title' => 'Feed',
    'description' => '',
    'link' => site()->url(),
    'urlfield' => 'url',
    'titlefield' => 'title',
    'datefield' => 'date',
    'textfield' => 'text',
    'modified' => time(),
    'snippet' => 'feed/rss', // 'feed/json'
    'dateformat' => 'r',
    'mime' => null,
    'sort' => true,
]

return [
    'routes' => [
        [
            'pattern' => 'feed',
            'method' => 'GET',
            'action'  => function () {
                $options = [
                    'title'       => 'Latest articles',
                    'description' => 'Read the latest news about our company',
                    'link'        => 'blog'
                ];
                $feed = page('blog')->children()->listed()->flip()->limit(10)->feed($options);
                return $feed;
            }
        ],
    ],
];

<link rel="alternate" type="application/rss+xml" title="Latest articles" href="<?= site()->url() 

<link rel="alternate" type="application/json" title="Latest articles" href="<?= site()->url() 

$feed = page('blog')->children()->listed()->sortBy(function ($page) {
 return $page->date()->toDate();
}, 'desc')->limit(10)->feed($options);

[
    'dateformat' => 'c',
    'xsl' => true,
    'urlfield' => 'url',
    'modified' => time(),
    'snippet' => 'feed/sitemap',
    'mime' => null,
    'sort' => true,
    'images' => false,
    'imagesfield' => 'images',
    'imagetitlefield' => 'title',
    'imagecaptionfield' => 'caption',
    'imagelicensefield' => 'license',
    'videos' => false,
    'videosfield' => 'videos',
    'videotitlefield' => 'title',
    'videothumbnailfield' => 'thumbnail',
    'videodescriptionfield' => 'description',
    'videourlfield' => 'url',
]

return [
    'routes' => [
        // ... other routes,
        [
            'pattern' => 'sitemap.xml',
            'method' => 'GET',
            'action'  => function () {
                $options = [
                    'images'       => false,
                    'videos'       => false,
                ];
                $feed = site()->index()->listed()->limit(50000)->sitemap($options);
                return $feed;
            }
        ],
        // (optional) Add stylesheet for human readable version of the xml file.
        // With that stylesheet visiting the xml in a browser will per-generate the images.
        // The images will NOT be pre-generated if the xml file is downloaded (by google).
        [
            'pattern' => 'sitemap.xsl',
            'method' => 'GET',
            'action'  => function () {
                snippet('feed/sitemapxsl');
                die;
            }
        ],
    ],
];

$feed = site()->index()->listed()
    ->filterBy('template', '!=', 'excludeme')
    ->limit(50000)->sitemap($options);