PHP Classes

Simple PHP SiteMap Generator: Generate XML and text sitemaps from lists of pages

Recommend this page to a friend!
  Info   View files Example   View files View files (9)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2023-10-05 (8 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 67 All time: 10,333 This week: 63Up
Version License PHP version Categories
simplesitemapgenerat 1.0Custom (specified...5XML, PHP 5, Tools, Files and Folders, T...
Description 

Author

This package can generate XML and text sitemaps from lists of pages.

It can take an array with lists of site pages and generate sitemap files.

Currently, the package generates sitemaps in XML or text format that show one site page URL per line.

Picture of Computing Mongoose
Name: Computing Mongoose <contact>
Classes: 1 package by
Country: Romania Romania
Age: ???
All time rank: 446881 in Romania Romania
Week rank: 259 Up5 in Romania Romania Up

Instructions

This is a PHP utility for generating a SiteMap.

The generation can be as easy as providing a list of files with a base URL (see example1) or, more complex, giving individual options for different files (see example2).

The generated file can be either in XML or TXT format.

The generated file can be used for indexing a website in a search engine, such as Google.

For more details about the file format, see [https://sitemaps.org/protocol.html].

Its primary intended usage is for generating sitemaps for static Web sites. You pass an array of file paths and get a sitemap file generated in the specified destination path.

The generation process will assign a different change frequency and priority to index files.

However, the generation process can be fully controlled by passing a detailed array of options to the generation process, as detailed below.

Take a look at the examples folder for different usage scenarios.

Example

<?php

require_once "../../SimpleSiteMapGenerator.php";

$pages=[
"index.html",
"file1.html",
"file2.html"
];

$sgen=new SimpleSiteMapGenerator();
$sgen->setBaseURL("https://mywebsite");
$sgen->generateSiteMapXML($pages);
$sgen->generateSiteMapTXT($pages);



Details

SimpleSiteMapGenerator

This is a PHP utility for generating a SiteMap. Generation can be as easy as providing a list of files with a base URL (see example1) or more complex, providing individual options for different files (see example2). The generated file can be either in XML or TXT format. The generated file can be used for indexing a website in a search engine, such as Google. For more details about the file format see: https://sitemaps.org/protocol.html .

Its primary intended usage is for generating sitemaps for static websites. You pass an array of file paths and get a sitemap file generated in the specified destination path. The generation process will assign a different change frequency and priority to index files. However, the generation process can be fully controlled by passing a detailed array of options to the generation process, as detailed below. Take a look at the examples folder for different usage scenarios.

Methods

generateSiteMapXML($pages)

This method will generate a sitemap file in XML format. The "pages" argument is an array with the pages to be included in the sitemap. Each entry contains either: - a) a string representing the page (file on the file system or a complete http(s) URL) - b) an array containing some or all of the following (missing elements are replaced with default values): - _page_ is the file or URL - _lastmod_ is the last modification string to be included in the sitemap - _changefreq_ is the change frequency string to be included in the sitemap - _priority_ is the priority string to be included in the sitemap

generateSiteMapTXT($pages)

This method will generate a sitemap file in TXT format. The "pages" argument is an array with the pages to be included in the sitemap, similar to the _generateSiteMapXML_ method. Since the TXT sitemap contains only URLs, other options such as _lastmod_, _changefreq_, and _priority_ are ignored.

setBaseURL($url)

Sets the base URL of the website. This will be used to generate URLs from file names. Example: _setBaseURL("https://mywebsite")_.

setDestinationPath($path)

Sets the destination folder location for the generated sitemap(s). This is checked and removed from file names if present. Example: _setDestinationPath("..")_.

setDefaultChangeFreq($freq)

Sets the default update frequency of files. This will be used in the XML sitemap. Example: _setDefaultChangeFreq("monthly")_.

setDefaultPriority($priority)

Sets the default priority of files. This will be used in the XML sitemap. Example: _setDefaultPriority("0.5")_.

setDefaultChangeFreqIndex($freq)

Sets the default update frequency of files containing the word "index" in the file name. This will be used in the XML sitemap. Example: _setDefaultChangeFreqIndex("weekly")_.

setDefaultPriorityIndex($priority)

Sets the default priority of files containing the word "index" in the file name. This will be used in the XML sitemap. Example: _setDefaultPriorityIndex("0.8")_.

Youtube

Checkout my YouTube channel for interesting videos: https://www.youtube.com/@ComputingMongoose/

Website

Checkout my website: https://ComputingMongoose.github.io


  Files folder image Files  
File Role Description
Files folder imageexamples (2 directories)
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation
Plain text file SimpleSiteMapGenerator.php Class Class source

  Files folder image Files  /  examples  
File Role Description
Files folder imageexample1 (3 files)
Files folder imageexample2 (3 files)

  Files folder image Files  /  examples  /  example1  
File Role Description
  Accessible without login Plain text file example1.php Example Example script
  Accessible without login Plain text file sitemap.txt Output Site URLs list
  Accessible without login Plain text file sitemap.xml Output XML Sitemap

  Files folder image Files  /  examples  /  example2  
File Role Description
  Accessible without login Plain text file example2.php Example Example script
  Accessible without login Plain text file sitemap.txt Output Site URLs list
  Accessible without login Plain text file sitemap.xml Output XML sitemap

 Version Control Unique User Downloads Download Rankings  
 100%
Total:67
This week:0
All time:10,333
This week:63Up