Advertisement
brasofilo

Custom XML from Wordpress Gallery to Flash

Oct 6th, 2011
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.68 KB | None | 0 0
  1. <?php
  2. /*
  3.  * Custom XML file to be read by Flash SWF
  4.  * Install : wp-content/gallery.xml.php
  5.  * Description : Grabs two custom fields from post 101 and generates a configuration XML file
  6.  * Dependencies : must adjust wp-load.php path in case this file is not inside wp-content/
  7.  * Usage : within Flash, call this XML generator and assign the correct POST_ID: "http://yourdomain.com/wp-content/gallery.xml.php?id=POST_ID"
  8.  * Observations: pay attention to the use of single and double quotes within the $xml variable
  9.  */
  10.  
  11. require_once "../wp-load.php";
  12. $id = intval($_GET['id']);
  13.  
  14. function GetGallery($idi){
  15.     $idi = intval($idi);
  16.     $img = array();
  17.     $results = get_children( array(
  18.         'post_parent' => $idi,
  19.         'post_status' => 'inherit',
  20.         'post_type' => 'attachment',
  21.         'post_mime_type' => 'image',
  22.         'order' => 'ASC',
  23.         'orderby' => 'menu_order') );
  24.     foreach ( $results as $imagem )
  25.     {
  26.         $pic=wp_get_attachment_image_src( $imagem->ID, 'medium' );
  27.         $title = $imagem->post_title;
  28.         $txt = $imagem->post_content;
  29.         $img[] = array('href' => $pic[0], 'title' => $title, 'txt' => $txt);
  30.     }
  31.     return $img;
  32. }
  33.  
  34. $GAL = GetGallery($id);
  35.  
  36. $xml = '<?xml version="1.0" encoding="UTF-8"?>' . "\n\n";
  37. $xml .= '<gallery>' . "\n\n";
  38.  
  39. $xml .= '<options>' . "\n\n";
  40. $xml .= '    <name>ONE OF MANY</name>' . "\n\n";
  41. $xml .= '</options>' . "\n\n";
  42.  
  43. $xml .= '<pictures>' . "\n\n";
  44. foreach($GAL as $jpg) {
  45.     $xml .= '    <pic>' . "\n";
  46.     $xml .= '        <bigimage>' . $jpg['href'] . '</bigimage>' ."\n";
  47.     $xml .= '        <info title="'. $jpg['title'] .'" desc="'. $jpg['txt'] .'" />' . "\n";
  48.     $xml .= '    </pic>' . "\n\n";
  49. }
  50. $xml .= '</pictures>' . "\n\n";
  51. $xml .= '</gallery>';
  52.  
  53. echo $xml;
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement