WordPress -> XML -> Flash
-
saw some old topics about, but apparently no solutions, so here are mines
i use this for feeding swf’s with xml generated by wordpress
so, instead of giving myfile.xml as reference to flash, i give myfile.xml.phpexample 1, config.xml.php, simple custom field query of post with id 101
<?php require_once "../wp-load.php"; $phone = get_post_meta(101, 'phone', true); $email = get_post_meta(101, 'email', true); $xml = <<<EOT <data> <settings> <phone>{$phone}</phone> <email>{$email}</email> </settings> </data> EOT; echo $xml; ?>
example 2, gallery.xml.php?id=POST_ID, full gallery of a post, got to feed the id in the url
<?php require_once "../wp-load.php"; $id = intval($_GET['id']); function GetGallery($idi){ $idi = intval($idi); $img = array(); $results = get_children( array( 'post_parent' => $idi, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order') ); foreach ( $results as $imagem ) { $pic=wp_get_attachment_image_src( $imagem->ID, 'medium' ); $title = $imagem->post_title; $txt = $imagem->post_content; $img[] = array('href' => $pic[0], 'title' => $title, 'txt' => $txt); } return $img; } $GAL = GetGallery($id); $xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n\n"; $xml .= '<gallery>' . "\n\n"; $xml .= '<options>' . "\n\n"; $xml .= ' <name>ONE OF MANY</name>' . "\n\n"; $xml .= '</options>' . "\n\n"; $xml .= '<pictures>' . "\n\n"; foreach($GAL as $jpg) { $xml .= ' <pic>' . "\n"; $xml .= ' <bigimage>' . $jpg['href'] . '</bigimage>' ."\n"; $xml .= ' <info title="'. $jpg['title'] .'" desc="'. $jpg['txt'] .'" />' . "\n"; $xml .= ' </pic>' . "\n\n"; } $xml .= '</pictures>' . "\n\n"; $xml .= '</gallery>'; echo $xml; ?>
important:
– path to wp-load.php, in these examples the files are inside /wp-content
– attention to the use of single and double quotesi used 2 techniques to echo the xml, the first example uses one i discovered recently
i think the second example opens the door to very complex xml structures
you can try it saving the code as gallery.xml.php inside your wp-content, and then go to the address: https://yousite.com/wp-content/gallery.xml.php?id=ID-OF-DESIRED-POSTgood luck
??
- The topic ‘WordPress -> XML -> Flash’ is closed to new replies.