logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$30
XML/RSS data feeds integration

I need help to pull an XML / RSS feed in a WordPress page.

This is how the feed will need to show in the end (the HTML/CSS is written already)
http://cl.ly/0A0X260C0u0B2y0I1f2y

Here is a sample of the feed provided by Ticketsoft:


<advShowtimesRow>
<TheatreID>1008</TheatreID>
<title>The Avengers - PG13 - 140 mins</title>
<link>
https://domain.aspx?theatreid=1008&ShowDate=05/31/2012
</link>
<description>05/31/2012 3:30PM</description>
<pubDate>05/31/2012</pubDate>
<BusinessDate>05/31/2012</BusinessDate>
<Enclosure>
http://domain.com/images/MoviePosters/4918.jpg
</Enclosure>
<TSMovieID>4918</TSMovieID>
</advShowtimesRow>


The date dropdown would need to sort the feeds by date, and there four locations with separate id's so we need to pull the feed based on location id.

Does anyone have experience or can help? Do we need a plugin or function?

This question has been answered.

Lucian Florian | 05/31/12 at 10:45am Edit


(2) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    05/31/12
    10:52am
    Hai Bui says:

    Hi,

    Wordpress provides fetch_feed function to retrieve an external feed and parse it. Is it what you need?
    http://codex.wordpress.org/Function_Reference/fetch_feed


    <?php // Get RSS Feed(s)
    include_once(ABSPATH . WPINC . '/feed.php');

    // Get a SimplePie feed object from the specified feed source.
    $rss = fetch_feed('http://example.com/rss/feed/goes/here');
    if (!is_wp_error( $rss ) ) : // Checks that the object is created correctly
    // Figure out how many total items there are, but limit it to 5.
    $maxitems = $rss->get_item_quantity(5);

    // Build an array of all the items, starting with element 0 (first element).
    $rss_items = $rss->get_items(0, $maxitems);
    endif;
    ?>

    <ul>
    <?php if ($maxitems == 0) echo '<li>No items.</li>';
    else
    // Loop through each feed item and display each item as a hyperlink.
    foreach ( $rss_items as $item ) : ?>
    <li>
    <a href='<?php echo esc_url( $item->get_permalink() ); ?>'
    title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'>
    <?php echo esc_html( $item->get_title() ); ?></a>
    </li>
    <?php endforeach; ?>
    </ul>

    Previous versions of this answer: 05/31/12 at 10:52am

    • 05/31/12 11:20am

      Lucian Florian says:

      I tried your code and I get a message text "no items" even if I tried to raise the max limit.

      Here is the HTML (of course images, title, times etc will need to be pulled from the feed):


      <!-- listing -->
      <div class="listing-wrap clearfix">
      <a href="i/pop-up-img.jpg" class="show-thumb preview"><img src="i/show-listing-thumb.jpg" alt="show-listing-thumb" width="50" height="75" /></a>
      <div class="show-listing">
      <h2 class="show-title">21 JUMP STREET (2012)</h2>
      <span class="smalltext darkgrey">110 mins R Digital</span>
      <ul class="show-times clearfix">
      <li>2:20 </li>
      <li><a href="#">4:55</a></li>
      <li><a href="#">5:30</a></li>
      <li><a href="#">7:05</a></li>
      <li> <a href="#">8:30</a></li>
      <li><a href="#">11:40</a></li>
      </ul>
      </div>
      </div>
      <!-- listing -->

    • 05/31/12 11:25am

      Hai Bui says:

      Oh, sorry, I've just realized that function won't work for you. You should go with John's solution. If you need to sort/filter the items, you have to loop through the items and store them into an array.

  • avatar
    Last edited:
    05/31/12
    10:55am
    John Cotton says:

    If I were you, I'd write my own function - plugins rarely do precisely what you want.

    You can use something like this to get data:

    if( $xml = simplexml_load_file($request_url) ) {
    // Do something with $xml
    // e.g. if <shows> is a list of those available then
    foreach( $xml->shows as $show ) {
    // output the info
    }
    }


    If the XML is neatly laid out, you should be able to use asort to sort the array as you want. After that, you can just output the data into your HTML.

    • 05/31/12 11:28am

      Lucian Florian says:

      Hey John, what would be the suggested prize to help with coding that solution?

    • 05/31/12 11:34am

      John Cotton says:

      Well, you can hire me for $100 an hour, but let's see if we can't get you there before that's necessary ;)

      1/ Do you have a single url to get the XML back?
      2/ If you do, stick it in the code above, add a print_r($xml) within the if statement and send me a link to a page with the output.

    • 05/31/12 12:15pm

      Lucian Florian says:

      sent a PM

    • 05/31/12 12:24pm

      John Cotton says:

      I'm not quite sure what your output is supposed to be, but this should give you enough to tweak to what you actually want.....


      function sort_by_date($a, $b) {
      $a_time = strtotime($a->BusinessDate);
      $b_time = strtotime($b->BusinessDate);

      if ($a_time == $b_time) {
      return 0;
      }
      return ($a_time < $b_time) ? -1 : 1;
      }


      if( $xml = simplexml_load_file($request_url) ) {
      usort($xml->AdvShowtimesDetailRow, 'sort_by_date'); // sorts the main array by date ASC

      $shows = array(); // Empty array to hold our HTML

      foreach( $xml->AdvShowtimesDetailRow as $show ) {
      $shows[] = sprintf( '<option value="%d">%s</option>', $show->TSMovieID, $show->title );
      }

      echo '<select id="shows">'.implode( '', $shows ).</select>'; // join the option elements and output
      }

    • 06/01/12 8:58am

      Lucian Florian says:

      Hey John, thanks. Your solution is good and I have somebody helping me with the implementation.

This question has expired.



Gabriel Reguly, Lucian Florian, Jurre Hanema, Arnav Joy voted on this question.



Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.