Coder Social home page Coder Social logo

aterbonus / sitemap Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thepixeldeveloper/sitemap

1.0 2.0 0.0 210 KB

PHP XML sitemap generation for PHP ^5.6 forked from https://github.com/ThePixelDeveloper/Sitemap

License: MIT License

PHP 100.00%
sitemap xml sitemap-php sitemap-builder sitemap-generator sitemap-xml xml-sitemap php-5

sitemap's Introduction

Aterbonus\Sitemap

WARNING: This is a quick repo from thepixeldeveloper/sitemap to make it work on PHP ^5.6. You should use the original repo if you have access to PHP 7. Don't expect updates.

Installation

composer require "Aterbonus/sitemap"

Basic Usage

Generating a typical (<urlset>) sitemap.

<?php

use Aterbonus\Sitemap\Urlset;
use Aterbonus\Sitemap\Url;
use Aterbonus\Sitemap\Drivers\XmlWriterDriver;

$url = new Url($loc);
$url->setLastMod($lastMod);
$url->setChangeFreq($changeFreq);
$url->setPriority($priority);

$urlset = new Urlset();
$urlSet->add($url);

$driver = new XmlWriterDriver();
$urlset->accept($driver);

echo $driver->getOutput();

Generating a parent (<sitemapindex>) sitemap.

<?php

use Aterbonus\Sitemap\SitemapIndex;
use Aterbonus\Sitemap\Sitemap;
use Aterbonus\Sitemap\Drivers\XmlWriterDriver;

// Sitemap entry.
$url = new Sitemap($loc);
$url->setLastMod($lastMod);

// Add it to a collection.
$urlset = new SitemapIndex();
$urlSet->add($url);

$driver = new XmlWriterDriver();
$urlset->accept($driver);

echo $driver->output();

Extensions

The following extensions are supported: Image, Link, Mobile, News and Video. They work in the following way (taking image as an example):

<?php

use Aterbonus\Sitemap\Urlset;
use Aterbonus\Sitemap\Url;
use Aterbonus\Sitemap\Extensions\Image;

$url = new Url($loc);
$url->setLastMod($lastMod);
$url->setChangeFreq($changeFreq);
$url->setPriority($priority);

$image = new Image('https://image-location.com');

$url->addExtension($image);

...

Advanced Usage

Processing Instructions

You can add processing instructions on the output as such.

<?php

use Aterbonus\Sitemap\Drivers\XmlWriterDriver;

$driver = new XmlWriterDriver();
$driver->addProcessingInstructions('xml-stylesheet', 'type="text/xsl" href="/path/to/xslt/main-sitemap.xsl"');

Which will add before the document starts.

<?xml-stylesheet type="text/xsl" href="/path/to/xslt/main-sitemap.xsl"?>

Comments

Comments are useful for information such as when the file was created.

<?php

use Aterbonus\Sitemap\Drivers\XmlWriterDriver;

$date = date('Y-m-d H:i:s');

$driver = new XmlWriterDriver();
$driver->addComment('This XML file was written on ' . $date . '. Bye!');

Which will render out.

<?xml version="1.0" encoding="UTF-8"?>
<!--This XML file was written on 2018-06-24 15:57:23. Bye!-->

sitemap's People

Contributors

aterbonus avatar handybitesize avatar hkdobrev avatar jacobemerick avatar johnblackmore avatar lushc avatar marcw avatar masnathan avatar nicolas-brousse avatar nucreativa avatar shashikreddy avatar sherault avatar svenluijten avatar thepixeldeveloper avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.