Need some help on displaying pods results (definitely a PEBKAC issue).

0

Okay, down to the issue - I am calling information from the pods "Events".

My problem is that I firstly need to display 1 Recently added item under a heading called "Current Events". Then under that I need a heading called "Past Events" - which needs to display all the other items that have been added to "Events" excluding the one that's displaying in Current Events.

For the Current Events, I limited my results to 1 :

<?php
          $singleenews = new Pod('events');
          $singleenews->findRecords('id DESC',1);
          $total_singleenews= $singleenews->getTotalRows();
?>

I'm just not to sure how to call the Past Events - where it excludes the most recently added item (that is being called in Current events).

So Current Events will display "October 2011" and Past Events will miss October and display "September 2011, August 2011, etc"

Any help would be greatly appreciated.

asked Oct 17 '11 at 11:25

sniperbob

3

edited Oct 17 '11 at 11:26

add comment
enter at least 15 characters

3 Answers

1

Try this:

$pods = new Pod ('events');
$pods->findRecords('id DESC', 1); //You probably want to use a date field here instead of the id...
$current_event_id = $pods->getField('id'); //You could also do this off the slug
echo "<h1>Current Events</h1>\n";
$pods->showTemplate('current-events');

$pods->findRecords('id DESC', -1, "t.id != $current_event_id");
echo "<h1>Past Events</h1>\n";
$pods->showTemplate('past-events');

answered Oct 17 '11 at 5:15

chris.pilko

889

add comment
enter at least 15 characters
0

Doh! I never thought of that. It's always so simple once someone points it out. Thank you so much for the help, much appreciated.

Here's the working code for the current event :

<?php
$currentevent = new Pod('events');
$currentevent->findRecords('id DESC',1);
$total_currentevent= $currentevent->getTotalRows(); ?>
<?php if( $total_currentevent>0 ) : ?>
    <?php while ( $currentevent->fetchRecord() ) : ?>
        <?php                                  
             $enews_id              = $currentevent->get_field('id');
             $enews_name            = $currentevent->get_field('name');
             $enews_pdf                 = $currentevent->get_field('pdf');
             $enews_description      = $currentevent->get_field('description');          
             $enews_pdf             = $enews_pdf[0]['guid'];

             $enews_description       = wpautop( $enews_description );
             $enews_image = $currentevent->get_field('thumb.ID');
             $arImage = wp_get_attachment_image_src($enews_image,'thumbnail');
             $strImageSrc = $arImage[0];
             $iImageWidth = $arImage[1];
             $iImageHeight = $arImage[2];
        ?>

        <?php if ($enews_name )  { ?>
            <div class="enews-title"><?php echo $enews_name; ?></div>
        <?php    }  ?> 
        //and the rest of the template info will be here.

 <?php endwhile ?>                               
<?php endif ?>

And past events code :

<p>
    <strong>Past e-News</strong>
</p>
<?php
    $pastnews = new Pod('events');
    $pastnews->findRecords('id DESC', 10, 't.id != "' . $enews_id . '"');
    $total_pastnews= $pastnews->getTotalRows();
?>
<?php if( $total_pastnews>0 ) : ?>
 <?php while ( $pastnews->fetchRecord() ) : ?>
        // and the rest of all the values and template stuff
  <?php endwhile ?>                              
<?php endif ?>

Again, thank you.

answered Oct 18 '11 at 7:43

sniperbob

3

add comment
enter at least 15 characters
0

Just to reemphasize what Chris said earlier -- you are probably going to want to use a date-based field in your findRecords -- not id. The ID will work as long as you add news in order, but if you have a news date that out of order, you're not going to get your news items chronologically.

answered Oct 19 '11 at 7:30

magi182

110

add comment
enter at least 15 characters