Display Next Record

2 posts by 2 authors in: Forums > CMS Builder
Last Post: May 16, 2018   (RSS)

By osga - May 16, 2018

Hello guys.

We are working with a new website template and there is a slider image and related news article(s). Each 'slide' should display the next article by date posted. I thought we could just use the [1] after $articlesRecords ($articlesRecords[1], but obviously that doesn't work. I also tried to create the next article  by using 'offset', which works to a point but throws errors and certainly can't be the way to  do this (below) . . . Any assitance would  be greatly appreciated.

// load record from 'articles'
list($articlesRecords2, $articlesMetaData) = getRecords(array(
'tableName' => 'articles',
'where' => '', // load second record
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
'offset' => '1',
));

SO....Here what we have so far:

<?php
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */

// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/var/www/sites/www.osga.com/html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load record from 'articles'
list($articlesRecords, $articlesMetaData) = getRecords(array(
'tableName' => 'articles',
'where' => '', // load first record
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));


?>

********************

<div class="caroufredsel_wrapper caroufredsel_wrapper_slider">
<ul class="slider">
<li class="slide">
<img src='images/slider/image_01.jpg' alt='img'>
<div class="slider_content_box">
<ul class="post_details simple">
<li class="category"><?php echo htmlencode($articlesRecord['art_field1']) ?></li>
<li class="date">
<?php echo date("D, M jS, Y g:i:s a", strtotime($articlesRecord['date'])) ?>
</li>
</ul>
<h2><div>
<?php foreach ($articlesRecords as $record): ?>

<a href="<?php echo $record['_link'] ?>" target="new"><?php echo $record['title'] ?></a><br/>
<p class="clearfix"><?php echo $record['summary'] ?></p>
<?php endforeach ?>

<?php if (!$articlesRecords): ?>
No records were found!<br/><br/>
<?php endif ?></div>
<!-- /Slide2: Display -->
</div>
</li>
<li class="slide">
<img src='images/slider/image_01.jpg' alt='img'>
<div class="slider_content_box">
<ul class="post_details simple">
<li class="category"><?php echo $articlesRecord[1]['categoryNum:label'] ?></li>
<li class="date">
<?php echo date("D, M jS, Y g:i:s a", strtotime($articlesRecord[1]['date'])) ?>
</li>
</ul>
<h2><div>
<?php foreach ($articlesRecords[1] as $record): ?>
<a href="<?php echo $record['_link'] ?>" target="new"><?php echo $record['title'] ?></a><br/>
<p class="clearfix"><?php echo $record['summary'] ?></p>
<?php endforeach ?>

<?php if (!$articlesRecords[1]): ?>
No records were found!<br/><br/>
<?php endif ?></div>