En cours

PHP Script to generate sitemap XML data from wordpress.

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: /[url removed, login to view])

* <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("[url removed, login to view]", "w");

fwrite($fileHandle,

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

'<urlset xmlns="[url removed, login to view]"' .

' xmlns:xsi="[url removed, login to view]" ' .

' xsi:schemaLocation="[url removed, login to view]' .

' [url removed, login to view]">'

);

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="[url removed, login to view]">

<url>

<loc>[url removed, login to view]</loc>

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

<changefreq>monthly</changefreq>

<priority>0.8</priority>

</url>

</urlset>

Compétences : MySQL, PHP, WordPress

en voir plus : what is data structure in c, what is data structure, what is a data structure in c, what data structure, what are data structure, table data structure, sitemap changefreq, set in data structure, set data structure, print w 9, prefix top, prefix in data structure, php generate xml from xsd, index data structure, data structure set, data structure example, data structure.com, w-9 from, index php id, wordpress mysql php

Concernant l'employeur :
( 162 commentaires ) Oakland Park, United States

Nº du projet : #5881698