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

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

return [
    'routes' => [
        [
            'pattern' => 'feed',
            'method' => 'GET',
            'action'  => function () {
                $options = [
                    'title' => 'Latest articles',
                    'description' => 'Read the latest news about our company',
                    'link' => 'blog',
                    'feedurl' => site()->url() . '/feed/', // matches pattern above
                ];
                
                // while this would be possible
                // return page('blog')->children()->listed()->flip()->limit(10)->feed($options);
                
                // using a closure allows for better performance on a cache hit
                return feed(fn() => page('blog')->children()->listed()->flip()->limit(10), $options);
            }
        ],
    ],
];

<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',
    'feedurl' => site()->url().'/sitemap.xml',
    'imagecaptionfield' => 'caption',
    'imagelicensefield' => 'license',
    'images' => false,
    'imagesfield' => 'images',
    'imagetitlefield' => 'title',
    'mime' => null,
    'modified' => time(),
    'snippet' => 'feed/sitemap',
    'sort' => true,
    'urlfield' => 'url',
    'videodescriptionfield' => 'description',
    'videos' => false,
    'videosfield' => 'videos',
    'videothumbnailfield' => 'thumbnail',
    'videotitlefield' => 'title',
    'videourlfield' => 'url',
    'xsl' => true,
]

return [
    'routes' => [
        // ... other routes,
        [
            'pattern' => 'sitemap.xml',
            'method' => 'GET',
            'action'  => function () {
                // while this would be possible
                // return site()->index()->listed()->limit(50000)->sitemap();
                
                // using a closure allows for better performance on a cache hit
                return sitemap(fn() => site()->index()->listed()->limit(50000));
            }
        ],
        // (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;
            }
        ],
    ],
];

return sitemap(fn() => site()->index()->listed()
    ->filterBy('template', '!=', 'excludeme')
    ->limit(50000)
);

\Bnomei\Feed::flush();