Create a gist now

Instantly share code, notes, and snippets.

Pagelime Page Listing using FTP-XML
function pagesForFolder($folderName) {
$pages = array();
// this is the path to the sitemap XML that Pagelime publishes
$pages_path = "/cms-assets/xml/sitemap.xml";
// if the XML file exists, keep going
if (file_exists($_SERVER["DOCUMENT_ROOT"].$pages_path)) {
// initialize an XML DOM Document
$xml = new DOMDocument;
$xml->preserveWhiteSpace = false;
// load the sitemap XML file
if ($xml->load($_SERVER["DOCUMENT_ROOT"].$pages_path)) {
// prepare an XPath navigator. we'll use this to find the right folder
$xpath = new DOMXPath($xml);
// find the page IDs for the requested folder name using XPath
$entries = $xpath->query("/Folder/Folders/Folder[Name=\"$folderName\"]/Files/Page/PageID");
// we'll use this array counter to push new pages into the return object
$count = 0;
// loop through the page IDs
foreach ($entries as $entry) {
// create a new array / page object in the return array $pages
$pages[$count] = array();
// get the $page_id from the looped elements
$page_id = $entry->textContent;
// this is the derived path of the XML for the specific page, based off the ID
$page_id_path = "/cms-assets/xml/pages/$page_id.xml";
// if it exits
if (file_exists($_SERVER["DOCUMENT_ROOT"].$page_id_path)) {
// load it
$xmlForPage = new DOMDocument;
$xmlForPage->preserveWhiteSpace = false;
if ($xmlForPage->load($_SERVER["DOCUMENT_ROOT"].$page_id_path)) {
// now do some xpath magic to find the page description and title
$xpathForPage = new DOMXPath($xmlForPage);
$description = $xpathForPage->query('/Page/MetaData/PageMetaData[@Name="description"]')->item(0)->getAttribute("Content");
$pages[$count]["description"] = $description;
$title = $xpathForPage->query('/Page/Title')->item(0)->textContent;
$pages[$count]["title"] = $title;
// increment the counter
// return the pages
return $pages;
<?php require("get-page-list-for-folder.php") ?>
<!-- so this is a piece of code that lists the title and description -->
<div id="news_page_list">
<?php foreach(pagesForFolder("news") as $page) { ?>
<h1><?php echo $page["title"]; ?></h1>
<p><?php echo $page["description"]; ?></p>
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment