Apple.com Style RSS Aggregator

Discussion in 'Web Design and Development' started by AtHomeBoy_2000, Feb 8, 2007.

  1. AtHomeBoy_2000 macrumors 6502a

    AtHomeBoy_2000

    Joined:
    Feb 3, 2005
    #1
    I would like to include a RSS aggregator very similar to the one on Apple.com (their "Hot News" section) on my webpage. I have tried my best to "reverse engineer" the aggregator, but with no success. Does anyone happen to know where I can find some resources to accomplish this? I have little to no training in programming.
     
  2. angelneo macrumors 68000

    Joined:
    Jun 13, 2004
    Location:
    afk
    #2
    I was about to say you can easily code that in javascript, but seeing you have minimal programming skills, that might be somewhat difficult.
     
  3. Mal macrumors 603

    Mal

    Joined:
    Jan 6, 2002
    Location:
    Orlando
    #3
    What about an explanation for those of us that can handle some programming? ;) I'm interested in the same type of thing, though I'd like to know if it can be done with PHP and/or CSS instead of JavaScript (I prefer the higher level of accessibility, plus I don't like coding JavaScript). I also wouldn't necessarily need live scrolling like on Apple's Hot News, though I suppose it could be nice (I teach a class on a bi-weekly basis, and would like to have a quick description and link that I don't have to manually update, since there's a set schedule for the classes).

    jW
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    30% of the solution

    Here's some code to get you started. It just goes over how to pull out the title tags. I print them out as a list, but you can do it a number of ways. You'd also create some CSS to style it however. (Disclaimer: Haven't tested this specific code.) Apple's implementation does look to use JavaScript for the fading in and out of headlines. JavaScript is needed though in some way to change the currently showing headline unless you want to use PHP to create a GIF image that goes through them. I don't recommend that though.

    PHP:
    $doc = new DomDocument();
    $doc->load("rss.xml");
    $titles $doc->getElementsByTagName('title');

    print 
    "<ul class='newsfeed'>\n";

    // Look at each title in RSS feed.
    // Alternatively you can do a for loop and just do 5 or whatever
    foreach ( $titles as $title ) {
      print 
    "  <li>"$title->nodeValue ."</li>\n";
    }
    print 
    "</ul>\n";
    As a suggestion for the JavaScript if you were to apply it to the list created here; I would hide each list item and switch between which one is currently being shown. Many ways to do it though.
     
  5. Mal macrumors 603

    Mal

    Joined:
    Jan 6, 2002
    Location:
    Orlando
    #5
    Thanks angelwatt, any recommendations on how to modify that to show a particular entry by date? Basically, if it's between the certain dates have it grab one entry, but between the next set of dates grab the next one? I can title the entries however I need to, but I'm not 100% sure the best way to make that work.

    jW
     
  6. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #6
    I don't completely follow that, but here's some code that can contribute to a solution I believe. RSS keeps the date of a post in the tag pubDate and is in the date format RFC-822. The code I gave before show how to get at the titles, and you can just as easily use it to get at the publish date tags. Then using the snippets of code below you can setup a for loop (or whatever) to see if that date is between these two.

    If this is done in a function you can pass back the index of a date that was found and use that to pull out the right item from the RSS. That is, if you pass back '2' from the function, you know the third (arrays start at 0) item is the one you care about. This allows you to do something like $it = $doc->getElementsByTagName('item')->item(x); where x is the value passed back from the function. Then you can do whatever with $it.

    PHP:
    $date1 date(DATE_RFC822mktime(0,0,0,2,1,2008)); // Feb 1, 2008
    $date2 date(DATE_RFC822); // today
    If you elaborate on your question I might be able to provide better help, though note I'm not overly knowledgeable on this and haven't created an aggregator myself.
     
  7. Mal macrumors 603

    Mal

    Joined:
    Jan 6, 2002
    Location:
    Orlando
    #7
    Thanks for your help, I'm obviously even less knowledgeable than you. ;)

    Basically, I'm doing all of this from scratch, so if there's a better method then I'm fine with changing, but here's my thoughts.

    I teach a class every other Saturday, and they're open to the public and at-will, so I want to publish the schedule on the company website (which I'm building now). I'd like to have the information regarding the next class or two coming up placed in a box on the front page of the site, with a link to more details and registration. I was planning at this point to simply publish that class schedule as an RSS feed, which I think I have an automated method of publishing from the same app I have to use to schedule the classes, and then simply pulling that information to fill the front page box, instead of having to duplicate the information there manually. Essentially, then, I just need each one to be displayed for a set period of time and then switch to the next one. I also wouldn't mind being able to pull the entire contents of that RSS feed and drop them into a php template page to make a page on the website that those not using RSS readers can access.

    Thanks again, I look forward to learning more!

    jW
     
  8. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #8
    Well I'm not sure RSS is the right way to go for a schedule. Schedules deal with what's coming up, whereas RSS is usually used for things that have happened already. If you can store the schedule in some type of calendar format (e.g., ical) you could possibly use PHP to look at that and get the upcoming events. Google calendars can also be embedded onto your page.
     
  9. Mal macrumors 603

    Mal

    Joined:
    Jan 6, 2002
    Location:
    Orlando
    #9
    iCal is fine with me, probably easier to do, but is that information that could be accessed via php? That's the key for me, I don't want an actual calendar on the page (it'll be linked to, but for the front page I just want a summary of the next item).

    If I could parse the current date and tell it to look ahead at the next 14 and find the one that has an event on that date, then that would be more than functional. Haven't ever gotten a chance to look at the code in an iCal file, but if that's possible, it might be a better way to go. I'll just have iCal publish the file to my web server and pull from that (I plan on allowing customers to subscribe to the iCal calendar anyways, so that's two birds with one stone).

    Thanks for your help, btw, this is really helping me to think through the options.

    jW
     
  10. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #10
    Well iCal is a plain text format, and thus harder to parse, but still do able. Apple has a page that talks about parsing it with Perl and PHP. It's a bit of code.

    Here's another code solution for parsing it into an array.

    I have an iCal based file for download at my site, but I don't try to parse it. I have it contain all my family's birthdays and anniversaries. I created the file from and XML file using XSLT. But I created my own XML scheme for my family to use. You could always create your own XML-iCal based format that would be easier to work with from a parsing perspective, but then you'll have to make a way to create the XML more easily, unless you're like me and enjoy typing in XML format. I'm just a geek like that.
     

Share This Page