PHP code example of b2bcat / sitemap

1. Go to this page and download the library: Download b2bcat/sitemap 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/ */

    

b2bcat / sitemap example snippets


use B2bcat\SiteMap\SiteMap;

$pages = [
    [
        'loc' => 'https://foo.me',
        'lastmod' => '2022-02-02 23.12.12',
        'priority' => 0.5,
        'changefreq' => 'daily' // hourly, daily, weekly
    ]   
];
$type = 'xml'; 
$path = '/var/www/site.ru/upload/sitemap.xml'

(new B2bcat\SiteMap(
    $pages,
    $type,
    $path
))

namespace App\Console\Commands;

use Illuminate\Console\Command;
use B2bcat\SiteMap\Laravel\SiteMapGenerator;
use B2bcat\SiteMap\Laravel\Generator\StaticRoute;
use B2bcat\SiteMap\Laravel\Generator\DynamicRoute;
use App\Models\Product;

class SiteMapGenerateCommand extends Command
{
    public $signature = 'sitemap:generate {file_type?}';

    public $description = 'Generate site map to file. Supported formats: xml, csv, json';

    public function handle (): int
    {
       $fileType = $this->hasArgument('file_type') ? $this->argument('file_type') : 'xml';
        
        (new SiteMapGenerator())
            ->route(
                (new StaticRoute())
                    ->setRouteName('products.list') // is 

// app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
    ...
    $schedule->command('sitemap:generate')->daily();
    ...
}