PHP code example of cwbit / cakephp-sitemap

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

    

cwbit / cakephp-sitemap example snippets


# somewhere in config/bootstrap.php

Plugin::load('Sitemap', [
    'routes' => true,
    ]);


	'Sitemap' => 
		'static' => 
			['_name' => 'pages:about'],
			'http://example.com/search',
			['controller'=>'Pages', 'action'=>'display', 'terms-of-service'],

	'Sitemap' => 
		'dynamic' => 
			'Items' =>  #the name of the model to get entities for
				'cachekey' => 'sitemap', 	# cachekey to use (e.g. from Configure::read('Cache.sitemap'))
				'finders' => [ .. ], 		# array of model-layer finders for getting entities
				'xmlTags' =>				# xml tags to output with each sitemap line
					'loc' => 'url'				# default 'url'; entity attribute name, or array, or string
					'priority' => 0.5			# default 0.5; 0 to 1 priority
					'lastmod' => 'updated'		# default 'updated'; entity attribute giving lastmod time
					'changefreq' => 'daily'		# default 'daily'; always, hourly, daily, weekly, yearly, never		
				


	# .. in config/app.php
	...,
    'Sitemap' => [
        'static' => [
            ['_name' => 'user-register'],
            ['_name' => 'user-resetpw'],
            ['_name' => 'user-login'],
            ['_name' => 'user-logout'],
            ['_name' => 'user-dashboard'],
            ['_name' => 'privacy'],
            ["_name" => "contact-us"],
            ["_name" => "rewards"],
            ["_name" => "terms-of-service"],
            ["_name" => "about-us"],            
            ["_name" => "search"],
        ],
        'dynamic' => [
            'Categories' => [
                'cacheKey' => 'sitemap',
                'finders' => [
                    'visible' => [],
                    ],
                'xmlTags'=> [
                    'loc' => 'url',
                    'priority' => '0.9',
                    'changefreq' => 'always',
                ],
            ],
            'Items' => [
                'cacheKey' => 'sitemap',
                'finders' => [
                    'visible' => [],
                    ],
                'xmlTags'=> [
                    'loc' => 'permalink',
                    'priority' => '0.9',
                    'changefreq' => 'always',
                ],
            ],
        ],
    ],