Loading ...
Sorry, an error occurred while loading the content.

Re: [SimplePie] Limiting SimplePie after sort

Expand Messages
  • Graham Lampa
    Nevermind. I figured it out! Inside the foreach loop that displays the items, I simply break after a counter has reached a certain point. $n = 1; foreach
    Message 1 of 7 , Aug 5, 2008
    View Source
    • 0 Attachment
      Nevermind. I figured it out!

      Inside the foreach loop that displays the items, I simply break after
      a counter has reached a certain point.

      $n = 1;

      foreach ($temp as $item) {
      if ($n == 4) {
      break;
      }
      /*Additional display stuff here*/
      echo $temp_event;

      $n++;
      }

      On Aug 5, 2008, at 9:44 AM, hammerikaner wrote:

      > Hi all,
      >
      > I've been using James Cridland's SimplePie implementation for
      > displaying Google Calendar
      > feeds (http://james.cridland.net/code/google-calendar.html), but
      > I've run into a problem:
      >
      > I can't figure out how to limit the number of items being displayed
      > after they
      > are sorted by event date. Check out this test page:
      >
      > http://blog.hhh.umn.edu/debug/googlecaltest.php
      >
      > Notice the first no-limit list of events has an event on Aug 5
      > (today). The second list omits
      > this event because it was added to the calendar after the other
      > events. Google Calendar's XML feed lists the events in
      >
      > So when I grab them using the (0, 3) method in "foreach ($feed-
      > >get_items(0,
      > 3) as $item)", it pulls the three most recently added events rather
      > than the three quickest upcoming events.
      >
      > I believe what I need to do is limit how many times the loop runs
      > through rendering the
      > HTML for the events after they are sorted rather than using the
      > foreach limit
      > to grab the first three events from the top of the feed (most
      > recently added).
      >
      > Can I do this with while? Or just a simple $n++; type limited in the
      > loop? How would I do
      > this? I'd appreciate it if someone could show me a code example.
      >
      > Thanks!
      >
      >
      > ------------------------------------
      >
      > Yahoo! Groups Links
      >
      >
      >
    • Michael Shipley
      Did you get this fixed because it look like its working now? Michael P. Shipley www.michaelpshipley.com
      Message 2 of 7 , Aug 5, 2008
      View Source
      • 0 Attachment
        Did you get this fixed because it look like its working now?

        Michael P. Shipley
        www.michaelpshipley.com


        hammerikaner wrote:
        Hi all,
        
        I've been using James Cridland's SimplePie implementation for displaying Google Calendar 
        feeds (http://james.cridland.net/code/google-calendar.html), but I've run into a problem:
        
        I can't figure out how to limit the number of items being displayed after they 
        are sorted by event date. Check out this test page:
        
        http://blog.hhh.umn.edu/debug/googlecaltest.php
        
        Notice the first no-limit list of events has an event on Aug 5 (today). The second list omits 
        this event because it was added to the calendar after the other 
        events. Google Calendar's XML feed lists the events in
        
        So when I grab them using the (0, 3) method in  "foreach ($feed->get_items(0, 
        3) as $item)", it pulls the three most recently added events rather 
        than the three quickest upcoming events.
        
        I believe what I need to do is limit how many times the loop runs through rendering the 
        HTML for the events after they are sorted rather than using the foreach limit 
        to grab the first three events from the top of the feed (most recently added).
        
        Can I do this with while? Or just a simple $n++; type limited in the loop? How would I do 
        this? I'd appreciate it if someone could show me a code example.
        
        Thanks!
        
        
        ------------------------------------
        
        Yahoo! Groups Links
        
        <*> To visit your group on the web, go to:
            http://groups.yahoo.com/group/simplepie-support/
        
        <*> Your email settings:
            Individual Email | Traditional
        
        <*> To change settings online go to:
            http://groups.yahoo.com/group/simplepie-support/join
            (Yahoo! ID required)
        
        <*> To change settings via email:
            mailto:simplepie-support-digest@yahoogroups.com 
            mailto:simplepie-support-fullfeatured@yahoogroups.com
        
        <*> To unsubscribe from this group, send an email to:
            simplepie-support-unsubscribe@yahoogroups.com
        
        <*> Your use of Yahoo! Groups is subject to:
            http://docs.yahoo.com/info/terms/
        
        
          
      • Graham Lampa
        Yes, got that fixed. But here s another one for you: On this page : http://www.hhh.umn.edu/centers/cspg/index2.php These blog headlines under Smart Politics
        Message 3 of 7 , Aug 6, 2008
        View Source
        • 0 Attachment
          Yes, got that fixed. But here's another one for you:


          These blog headlines under "Smart Politics" banner on right side are showing up with ??? in place of curly-quote apostrophes. The cache should have expired on that now since I replaced them in the MovableType blog with straight apostrophes, but they still show up incorrectly.

          Is there something with SimplePie I can do to make sure this does not happen? Something with UTF encoding? I am horribly ignorant of character encoding issues. I understand what it's all about, but I've never been able to wrap my head around the specifics.

          Graham

          On Aug 6, 2008, at 1:34 AM, Michael Shipley wrote:

          Did you get this fixed because it look like its working now?

          Michael P. Shipley
          www.michaelpshipley.com


          hammerikaner wrote:
          Hi all,
          
          I've been using James Cridland's SimplePie implementation for displaying Google Calendar 
          feeds (http://james.cridland.net/code/google-calendar.html), but I've run into a problem:
          
          I can't figure out how to limit the number of items being displayed after they 
          are sorted by event date. Check out this test page:
          
          http://blog.hhh.umn.edu/debug/googlecaltest.php
          
          Notice the first no-limit list of events has an event on Aug 5 (today). The second list omits 
          this event because it was added to the calendar after the other 
          events. Google Calendar's XML feed lists the events in
          
          So when I grab them using the (0, 3) method in  "foreach ($feed->get_items(0, 
          3) as $item)", it pulls the three most recently added events rather 
          than the three quickest upcoming events.
          
          I believe what I need to do is limit how many times the loop runs through rendering the 
          HTML for the events after they are sorted rather than using the foreach limit 
          to grab the first three events from the top of the feed (most recently added).
          
          Can I do this with while? Or just a simple $n++; type limited in the loop? How would I do 
          this? I'd appreciate it if someone could show me a code example.
          
          Thanks!
          
          
          ------------------------------------
          
          Yahoo! Groups Links
          
          <*> To visit your group on the web, go to:
              http://groups.yahoo.com/group/simplepie-support/
          
          <*> Your email settings:
              Individual Email | Traditional
          
          <*> To change settings online go to:
              http://groups.yahoo.com/group/simplepie-support/join
              (Yahoo! ID required)
          
          <*> To change settings via email:
              mailto:simplepie-support-digest@yahoogroups.com 
              mailto:simplepie-support-fullfeatured@yahoogroups.com
          
          <*> To unsubscribe from this group, send an email to:
              simplepie-support-unsubscribe@yahoogroups.com
          
          <*> Your use of Yahoo! Groups is subject to:
              http://docs.yahoo.com/info/terms/
          
          
            

        • Ryan Parman
          On the first issue, you can set start and length parameters in get_items() . On the second issue, you just need to make
          Message 4 of 7 , Aug 6, 2008
          View Source
          • 0 Attachment
            On the first issue, you can set start and length parameters in get_items() <http://ref.simplepie.org/get_items>.

            On the second issue, you just need to make sure that the feed is served with the same character encoding as what the content is actually in. It doesn't matter what the encoding is, as long as it's specified correctly. In the case of strange question marks, we've also provided a method for user-specified character encodings (e.g. for when YOU know better than the FEED what it is). <http://ref.simplepie.org/set_input_encoding> Of course, you'll need to know what the correct encoding is.

            And in terms of the cache, SimplePie will keep what's there for one hour by default -- regardless of what you've changed in your feed. SimplePie won't know the feed has changed until the initial cache expires after 60 minutes. You can force a refresh of the cache by deleting the files in the cache directory.

            Hope this helps! :)



            On Aug 6, 2008, at 8:41 AM, Graham Lampa wrote:

            Yes, got that fixed. But here's another one for you:


            These blog headlines under "Smart Politics" banner on right side are showing up with ??? in place of curly-quote apostrophes. The cache should have expired on that now since I replaced them in the MovableType blog with straight apostrophes, but they still show up incorrectly.

            Is there something with SimplePie I can do to make sure this does not happen? Something with UTF encoding? I am horribly ignorant of character encoding issues. I understand what it's all about, but I've never been able to wrap my head around the specifics.

            Graham

            On Aug 6, 2008, at 1:34 AM, Michael Shipley wrote:

            Did you get this fixed because it look like its working now?

            Michael P. Shipley
            www.michaelpshipley.com


            hammerikaner wrote:
            Hi all,
            
            I've been using James Cridland's SimplePie implementation for displaying Google Calendar 
            feeds (http://james.cridland.net/code/google-calendar.html), but I've run into a problem:
            
            I can't figure out how to limit the number of items being displayed after they 
            are sorted by event date. Check out this test page:
            
            http://blog.hhh.umn.edu/debug/googlecaltest.php
            
            Notice the first no-limit list of events has an event on Aug 5 (today). The second list omits 
            this event because it was added to the calendar after the other 
            events. Google Calendar's XML feed lists the events in
            
            So when I grab them using the (0, 3) method in  "foreach ($feed->get_items(0, 
            3) as $item)", it pulls the three most recently added events rather 
            than the three quickest upcoming events.
            
            I believe what I need to do is limit how many times the loop runs through rendering the 
            HTML for the events after they are sorted rather than using the foreach limit 
            to grab the first three events from the top of the feed (most recently added).
            
            Can I do this with while? Or just a simple $n++; type limited in the loop? How would I do 
            this? I'd appreciate it if someone could show me a code example.
            
            Thanks!
            
            
            ------------------------------------
            
            Yahoo! Groups Links
            
            <*> To visit your group on the web, go to:
                http://groups.yahoo.com/group/simplepie-support/
            
            <*> Your email settings:
                Individual Email | Traditional
            
            <*> To change settings online go to:
                http://groups.yahoo.com/group/simplepie-support/join
                (Yahoo! ID required)
            
            <*> To change settings via email:
                mailto:simplepie-support-digest@yahoogroups.com 
                mailto:simplepie-support-fullfeatured@yahoogroups.com
            
            <*> To unsubscribe from this group, send an email to:
                simplepie-support-unsubscribe@yahoogroups.com
            
            <*> Your use of Yahoo! Groups is subject to:
                http://docs.yahoo.com/info/terms/
            
            
              



            --
            Ryan Parman







          • Graham Lampa
            Hi Ryan, ... That s exactly what I *don t* want to do. Since I am taking the Google Calendar feed, it lists posts in most recently added order. I wanted them
            Message 5 of 7 , Aug 7, 2008
            View Source
            • 0 Attachment
              Hi Ryan,

              On the first issue, you can set start and length parameters in get_items() <http://ref.simplepie.org/get_items>.


              That's exactly what I *don't* want to do. Since I am taking the Google Calendar feed, it lists posts in most recently added order. I wanted them in upcoming event order. So get_items(0, 3) would not do what I want.

              Instead, ended up using a counter in the loop and then breaking the loop once it reached the limit I set. This is done after the sort by event date on the entire feed, sidestepping the issue of Google's weird-ass sorting of events by date added in the RSS.

              Graham

            • Ryan Parman
              Ah, gotcha. I keep forgetting that gCal has wonky sorting. ... -- Ryan Parman
              Message 6 of 7 , Aug 7, 2008
              View Source
              • 0 Attachment
                Ah, gotcha. I keep forgetting that gCal has wonky sorting.


                On Aug 7, 2008, at 7:32 AM, Graham Lampa wrote:

                Hi Ryan,

                On the first issue, you can set start and length parameters in get_items() <http://ref.simplepie.org/get_items>.


                That's exactly what I *don't* want to do. Since I am taking the Google Calendar feed, it lists posts in most recently added order. I wanted them in upcoming event order. So get_items(0, 3) would not do what I want.

                Instead, ended up using a counter in the loop and then breaking the loop once it reached the limit I set. This is done after the sort by event date on the entire feed, sidestepping the issue of Google's weird-ass sorting of events by date added in the RSS.

                Graham



                --
                Ryan Parman







              Your message has been successfully submitted and would be delivered to recipients shortly.