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

By claire - February 2, 2015

Hi Kurt

It would be good practice to keep them separate if you're going to use the sidebar in places where the most recent article doesn't appear. It's also simpler to deal with overall.

For the most recent article, you'll want a getRecords call that looks like this:

list($articleRecords, $articleMeta) = getRecords(array(
  'tableName' => 'articles',
  'orderBy' => 'createdDate DESC',
  'allowSearch' => false,
  'loadUploads' => true,
  'limit' => 1
));
$mostRecent = $articleRecords[0];

Obviously, you need to put the right table name in there if yours is called something other than 'articles'! Then you can just echo whatever you need out of $mostRecent.

For the sidebar:

list($articleRecords, $articleMeta) = getRecords(array(
  'tableName' => 'articles',
  'orderBy' => 'createdDate DESC',
  'allowSearch' => false,
  'loadUploads' => true,
  'limit' => 6
));
unset($articleRecords[0]);

This will get the six most recent articles (change this number to whatever you like) and then exclude the first one. All you should need to do is run $articleRecords through a foreach loop (see the Code Generator entry for multi-record viewers if you're not sure how this works) and echo the date, title, and author info in the sidebar for each one left.

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

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

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