Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm not looking for a sitemap, I'm looking to create an xml file that I can have a flash menu access, but I don't want to generate the XML file each time someone visits a page, I want to have a static XML to refer to for speed. And I'd like to have wordpress update the file whenever new content is posted(not comments).

Is there anything built into wordpress that would allow me to do this? Any plugins? Again, I don't want a sitemap. I want a specific list of items. Right now I've been using page templates with custom loops, but it takes to long to generate every time.

share|improve this question
    
See My answer on this link it is answered according to this question: http://wordpress.stackexchange.com/questions/15218/how-to-generate-update-a-xml‌​-sitemap-without-plugins/36856#36856 –  w3uiguru Dec 19 '11 at 10:45
add comment

3 Answers 3

up vote 0 down vote accepted

Hmm... not sure if there are any WordPress-specific functions for creating files. There's wp_handle_upload, but I'm not sure how you'd use it in this context.

Depending on your server configuration, you can probably just use fopen and fwrite to do this.

Keep the code you're currently using (with your custom loops...I'm assuming they contain the XML markup you want), but have it build the output as a string. Then save that string into a file. Something like:

// Build your file contents as a string
$file_contents = '<?xml version="1.0" ?><yourroot><item>some content</item></yourroot></xml>';

// Open or create a file (this does it in the same dir as the script)
$my_file = fopen("myfile.xml", "w");

// Write the string's contents into that file
fwrite($my_file, $file_contents);

// Close 'er up
fclose($my_file);

Of course, this all depends on your server config and permissions. Maybe someone has a better solution that only requires native WP functions.

share|improve this answer
    
the "have it build the output as a string" part I'm not sure about. would I put the URL like $file_contents = blog.com/sitetemplate –  Ghost9 Jan 13 '11 at 0:58
    
how would I go about getting that file called every time someone made a post? –  Ghost9 Jan 13 '11 at 1:13
    
ah! got an answer to that. Now my only question is, is there a way to set the save path? so i can pick the directory it saves in? –  Ghost9 Jan 13 '11 at 3:45
    
Sure. fopen should be able to accept a full local path (something like var/www/html/yoursitefolder/someotherfolder/yourfile.xml). Of course, this will depend on having the correct write permissions on that folder. –  MathSmath Jan 13 '11 at 4:39
1  
you can do this with one function called: file_put_contents(); - php.net/manual/en/function.file-put-contents.php –  hakre Jan 23 '11 at 1:02
add comment

Nothing built-in but you should look into the various sitemaps plugins. These will show you a) where to hook into and b) how to generate the file if you're not familiar with php file manipulation.

share|improve this answer
add comment

Take a look at the export_wp function.

Make a duplicate of it and keep only the stuff you want exported, then run this function every time a post is saved: add_action('save_post', 'my_export_wp');

(Make so the function sends its output to a xml file)

share|improve this answer
    
That file is a bit daunting for. I think i'll stick with the previous suggestion –  Ghost9 Jan 13 '11 at 6:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.