WordPress.org

Ready to get started?Download WordPress

Forums

Add WordPress code in XML file (1 post)

  1. Antonin
    Member
    Posted 4 years ago #

    Hi,

    I am working on a project to place Markers on a google map based on informations from certain posts (I will put the latitude and longitude infos on custom fields later).

    I am following this idea (http://articles.sitepoint.com/article/google-maps-api-jquery), slightly modified to work with wordpress. I transformed the XML file of the markers in php format to insert my wordpress query. Although I can make basic php code works (like an "echo"), I cannot retrieve the data from my wordpress posts.

    The javascript which places the markers is called in the header and the xml is called by the javascript.

    Here is my code at the moment for that specific php/xml file:

    <?xml version="1.0"?>
    
    <markers>
    
    <?php 
    
    $categories = get_categories('child_of=1');
    if ( $categories ) {
      foreach($categories as $category) {
          $posts=get_posts('showposts=1&cat='. $category->term_id);
          if ($posts) {
    
            foreach($posts as $post) {
              ?>
    
    		  <marker>
    <name><?php the_title(); ?></name>
    <address>text</address>
    <lat>17.75033553</lat>
    <lng>83.25067267</lng>
    </marker>
    
              <?php
            } // foreach($posts
          } // if ($posts
        } // foreach($categories
      } // if (categories
    
    ?>
    
    </markers>

    I don't know what I've missed.

    thanks in advance for any help/advice I can get.

Topic Closed

This topic has been closed to new replies.

About this Topic