Um alle WordPress-Funktionen und Klassen auch außerhalb der WordPress-Installation verwenden zu können, muss man nur die wp-config.php in das jeweilige Script includen. In diesem Snippet erstelle ich so beispielsweise ein XML-Feed meiner Blogposts indem ich die als global deklarierte Datenbank-Klasse $wpdb nutze.
<?php include_once('wordpress/wp-config.php'); function create_xml_feed(){ global $wpdb, $table_prefix; $result = $wpdb->get_results('SELECT * FROM '.$table_prefix.'posts WHERE post_status="publish" ORDER BY ID DESC'); $xml = '<?xml version="1.0" encoding="UTF-8" ?> <buildup>'; foreach($result as $post){ $xml .= ' <post id="'.$post->ID.'"> <ID>'.$post->ID.'</ID> <post_author><![CDATA['.$post->post_author.']]></post_author> <post_date>'.$post->post_date.'</post_date> <post_date_gmt>'.$post->post_date_gmt.'</post_date_gmt> <post_content><![CDATA['.$post->post_content.']]></post_content> <post_title><![CDATA['.$post->post_title.']]></post_title> <post_name>'.$post->post_name.'</post_name> <post_modified>'.$post->post_modified.'</post_modified> <post_modified_gmt>'.$post->post_modified_gmt.'</post_modified_gmt> <guid>'.$post->guid.'</guid> <comment_count>'.$post->comment_count.'</comment_count> </post>'; } file_put_contents('feed.xml', $xml.'</buildup>'); } ?>Als Textdatei öffnen | since1985de_e2304277.txt | 1.05 Kilobyte