PHP list viewer assistance please

5 posts by 3 authors in: Forums > CMS Builder
Last Post: February 4, 2015   (RSS)

By kkegans - January 30, 2015

I have a list page, blog page articles, and I would like to display only the most recent article in the webpage body, then display the date, title and author information of all of the remaining articles in a sidebar of the page.

Can some help me with the PHP code required to make that happen?

Or is it best to treat each part of the page separately and use separate PHP code for the main body and the sidebar?

Kurt

CMSB Rocks!
Thanks,
Kurt

I use something like this to format the first news article or event differently using only one viewer:

<?php
    // load records from 'news'
    list($newsRecords, $newsMetaData) = getRecords(array(
      'tableName'   => 'news',
      'loadUploads' => true,
      'allowSearch' => false,
      'limit'                => 6 // Max number to display in sidebar 
    ));
    $firstNewsRecord = $newsRecords[0]; // Get the first record as $firstNewsRecord
?>          
<?php if($newsRecords): // If any news exists ?>
  <!-- For the first record -->
  <div class="big-news">
    <!-- Place first news story in large format on page -->
    <h1><?php echo $firstNewsRecord['title'] ?></h1>
    <?php echo $firstNewsRecord['date'] ?>
    <?php echo $firstNewsRecord['content'] ?>
  </div>
  <!-- For the Sidebar, the rest of the records -->
  <div class="side-news">
      <?php foreach $newsRecords as $sideNews: // or whatever you want to call it ?>
        <?php if($count++ < 1){continue;} // Skip the first record ?> 
            <a href="<?php echo $sideNews['_link'] ?>"><?php echo $sideNews['title'] ?></a>
      <?php endforeach ?>
  </div> 
<?php else: ?>
  <!-- Inform no news exists message -->
  No news exists  
<?php endif ?>

Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987

By kkegans - February 3, 2015 - edited: February 3, 2015

Ron,  Thanks, that is exactly what I was looking for.  I was confused on how to use 2 different viewers on the same page, but your solution works beautifully!

CMSB Rocks!
Thanks,
Kurt

Glad I could be of assistance!

Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987