Advertisement
elbatron

wordpress XML

Sep 9th, 2011
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.20 KB | None | 0 0
  1. <?php
  2.     $new = new WP_Query('post_type=kml');
  3.     while ($new->have_posts()) : $new->the_post();
  4.         if(get_field('marker_datas')):
  5.         while(the_repeater_field('marker_datas')):
  6.             $name = the_sub_field('placemark_name');
  7. // it seems the variables don't store the values - can't echo them, I get only an empty h2
  8.             //echo '<h2>' , $name , '</h2>';
  9.             $description = the_sub_field('placemark_text');
  10.             $styleUrl = the_sub_field('placemark_style_id');
  11.             $Point = the_sub_field('placemark_coordinates');
  12.         endwhile;
  13.         endif;
  14.    
  15.         endwhile;
  16.  
  17. class Placemark
  18. {
  19.  
  20.   public $name;
  21.   public $description;
  22.   public $styleUrl;
  23.   public $Point;
  24.  
  25.   function __construct(
  26.     $name, $description, $styleUrl, $Point)
  27.   {
  28.     $this->name = $name;
  29.     $this->description = $description;
  30.     $this->styleUrl = $styleUrl;
  31.     $this->Point = $Point;
  32.   }
  33. }
  34.  
  35. //make placemark object
  36. $placemarks = array(
  37.   new Placemark(
  38. // these variables not working unless I type the values themselves here, the xml nodes are empty
  39.     'this is a placemarks name',
  40.     $description,
  41.     $styleUrl,
  42.     $Point
  43.   )
  44. );
  45.  
  46. //create the xml document
  47. $xmlDoc = new DOMDocument();
  48.  
  49. //create the root element
  50. $root = $xmlDoc->appendChild(
  51.           $xmlDoc->createElement("Document"));
  52.        
  53. foreach($placemarks as $marker)
  54. {
  55.   //create a marker element
  56.   $markerTag = $root->appendChild(
  57.               $xmlDoc->createElement("Placemark"));
  58.  
  59.   //create the name element
  60.   $markerTag->appendChild(
  61.     $xmlDoc->createElement("Name", $marker->name));
  62.    
  63.   //create the desc element
  64.   $markerTag->appendChild(
  65.     $xmlDoc->createElement("Description", $marker->description));
  66.  
  67.   //create the styleURL element
  68.   $markerTag->appendChild(
  69.     $xmlDoc->createElement("styleUrl", $marker->styleUrl));
  70.    
  71.   //create the coordinate element
  72.   $coordTag = $markerTag->appendChild(
  73.               $xmlDoc->createElement("Point"));
  74.     $coordTag->appendChild(
  75.       $xmlDoc->createElement("coordinates", $marker->Point));
  76. }
  77.  
  78. header("Content-Type: text/plain");
  79.  
  80. //make the output pretty
  81. $xmlDoc->formatOutput = true;
  82.  
  83. echo $xmlDoc->saveXML();
  84. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement