Adding a next previous navigation block to a News Detail page.

3 posts by 2 authors in: Forums > CMS Builder
Last Post: May 7, 2009   (RSS)

By dbown - May 6, 2009

I have a page newsDetail.php that displays the full content of any news release.

Also on this page is a sidebar listing the 10 most recent news releases with links to them.

I wish to add to this page a next previous news release navigation block that allow visitors to go back and forth in the news releases using the default display order of each news release to determine positioning.

I.e: if we released 3 news releases this week and a visitor was currently looking at the 2nd most recent, he would have the option to to click next to see the most recent or click previous to see the previous (older of the three) news releases.

The most recent news release of course would not let you view the next because there is none newer.

By clicking previous you could view all previous news releases (1 at a time) going back through the archives.

I do not require the running total of news releases to be provided between the next and previous links. (i.e.: no Page 23 of 459).

Below is my code and my failed buggy attempt to add the next-previous code block. The page is visible at http://www.canadasprayerguide.com/news_releases/newsDetail.php?Fast-links-to-09-Prairie-grasshopper-forecasts-2=&page=2

----------------------------------------

<!-- START CONTENT DISPLAY CODE -->
<?php

require_once "/home/canadasp/public_html/cmsAdmin/lib/viewer_functions.php";

list($news_releasesRecords, $news_releasesMetaData) = getRecords(array(
'tableName' => 'news_releases',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$news_releasesRecord = @$news_releasesRecords[0]; // get first record

// show error message if no matching record is found
if (!$news_releasesRecord) {
print "Record not found!";
exit;
}
?>
<!-- END CONTENT DISPLAY CODE -->

<!-- START NEXT - PREV CODE -->
<?php

require_once "/home/canadasp/public_html/cmsAdmin/lib/viewer_functions.php";

list($news_releasesNavRecords, $news_releasesNavMetaData) = getRecords(array(
'tableName' => 'news_releases',
'perPage' => '1',
));
?>
<!-- END NEXT - PREV CODE -->

<!-- START SIDEBAR CODE -->
<?php

require_once "/home/canadasp/public_html/cmsAdmin/lib/viewer_functions.php";

list($news_releasesSidebarRecords, $news_releasesSidebarMetaData) = getRecords(array(
'tableName' => 'news_releases',
'limit' => '10',
'allowSearch' => '0',
));
?>
<!-- END SIDEBAR CODE -->

-----------------------------



<!-- START NEWS RELEASE CONTENT -->
<h3><?php echo $news_releasesRecord['title'] ?></h3>
<p class="date">Posted: <?php echo date("F j, Y", strtotime($news_releasesRecord['date'])) ?></p>
<p class="deck"><?php echo $news_releasesRecord['deck'] ?></p>
<?php echo $news_releasesRecord['content'] ?>


<?php if (!$news_releasesRecord): ?>
No record found!<br/><br/>
<?php endif ?>
<!-- EBD NEWS RELEASE CONTENT -->



<br>

<hr/>




<!-- START NEXT - PREV LINKS -->
<?php if ($news_releasesNavMetaData['prevPage']): ?>
<a href="<?php echo $news_releasesNavMetaData['prevPageLink'] ?>">&lt;&lt; prev</a>
<?php else: ?>
&lt;&lt; prev
<?php endif ?>

- page <?php echo $news_releasesNavMetaData['page'] ?> of <?php echo $news_releasesMetaData['totalPages'] ?> -

<?php if ($news_releasesNavMetaData['nextPage']): ?>
<a href="<?php echo $news_releasesNavMetaData['nextPageLink'] ?>">next &gt;&gt;</a>
<?php else: ?>
next &gt;&gt;
<?php endif ?>
<!-- END NEXT - PREV LINKS -->

<hr/>




<!-- START SIDE BAR -->

<?php foreach ($news_releasesSidebarRecords as $recordSidebar): ?>

<h4 style="margin-bottom:8px; padding-top: 5px; border-top:1px solid #aaa;"><a href="<?php echo $recordSidebar['_link'] ?>"><?php echo $recordSidebar['title'] ?></a></h4>
<p class="date" style="margin-top:5px;">Posted: <?php echo date("F j, Y", strtotime($recordSidebar['date'])) ?></p>

<?php endforeach; ?>

<?php if (!$news_releasesSidebarRecords): ?>
No records were found!<br/><br/>
<?php endif ?>
<!-- END SIDE BAR -->

-------------------------------

Thanks,
Dave

Re: [dbown] Adding a next previous navigation block to a News Detail page.

By ross - May 7, 2009

Hi Dave

Thanks for posting!

Check out this post:


http://www.interactivetools.com/iforum/P66131#66131


I think that's exactly what you'll be looking for :).
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/