PHP Script to generate sitemap XML data from wordpress.

Pågår Lagt ut Apr 30, 2014 Betales ved levering
Pågår Betales ved levering

I need one php script written to generate a XML Sitemap of a Wordpress site.

Requirements

* Run one DB query to get the active permalink structure for the links.

* Toggle variable to either print xml data to screen or to file (file path EXAMPLE: /[login to view URL])

* <changefreq> should equal the modified date from DB

* <priority> should come from a variable I can set at the top of the script. I should be able to set it for pages and post separately.

* Run separate DB queries for pages and post. This way I can manually set the <priority> and <changefreq> for both pages and post.

* Echo data to screen or file as data comes in, do not buffer data. This way if I print to screen it will appear faster as data keeps loading

* all the pages and post need to be of published status.

* allow me to manually specify the post table name in case it has a different prefix or write code to automatically determine this prefix. by default it is wp_ but when installing you can select a different prefix.

* Add manual option to exclude certain ID's in case I do not want to index certain pages or post. I should have separate options for both pages and post. The excluded ID's should be added to the mysql query and not checked using PHP. If done using the mysql query it will cache the data for the query so future executions would be faster. Plus it would be less processing power if excluded from the DB query.

* Run DB query to determine the amount of total records and only pull 500 records at a time until all records are loaded. Iteration should be limited by the number of records

This one php script does not need to become a wordpress plugin. Just a stand alone file.

Example of code that is similar to what I am looking to do but needs to meet all my requirements.

<?php

$fileHandle = fopen("[login to view URL]", "w");

fwrite($fileHandle,

'<?xml version="1.0" encoding="UTF-8"?>' .

'<urlset xmlns="[login to view URL]"' .

' xmlns:xsi="[login to view URL]" ' .

' xsi:schemaLocation="[login to view URL]' .

' [login to view URL]">'

);

for ($i = 0 ; $i< 10; $i++) {

$query = mysql_query(sprintf("SELECT ID, post_date FROM wp_posts WHERE post_status='publish' LIMIT %s,%s", $i*500, 500));

$xml = '';

while ($row = mysql_fetch_array($query)) {

$xml .= '<url>'.

'<loc>'.get_permalink($row['ID']).'</loc>' .

'<lastmod>'.$row['post_date'].'</lastmod>' .

'<changefreq>weekly</changefreq>' .

'<priority>0.6</priority>' .

'</url>';

}

fwrite($fileHandle, $xml);

}

fwrite($fileHandle, '</urlset>');

fclose($fileHandle);

?>

EXAMPLE of output sitemap XML data:

<?xml version="1.0" encoding="UTF-8"?>

<urlset xmlns="[login to view URL]">

<url>

<loc>[login to view URL]</loc>

<lastmod>2005-01-01</lastmod>

<changefreq>monthly</changefreq>

<priority>0.8</priority>

</url>

</urlset>

MySQL PHP WordPress

Prosjekt-ID: #5881698

Om prosjektet

19 bud Eksternt prosjekt Aktiv May 1, 2014