Question about headlines on the footer

2 posts by 2 authors in: Forums > CMS Builder
Last Post: November 3, 2013   (RSS)

By Jesus - November 1, 2013

Hello,

I've my website almost ready to go but I just found something and I hope you can give me a clue on how to do this. Everything its working fine BUT this.

I've my footer showing the latest 2 headlines from my press releases table, and that works perfectly on all my pages around the website, however... when I came to my Press Release page I've an issue as I'm showing all my headlines on my index page and I also need to keep my footer showing the latest 2 headlines (from the same press releases table) to keep my footer uniform all over my website.

So here's the code I've on my header...

  // load records from 'press_releases'
  list($press_releasesRecords, $press_releasesMetaData) = getRecords(array(
    'tableName'   => 'press_releases',
    'loadUploads' => true,
    'allowSearch' => false,
  ));

  // load records from 'events'
  list($eventsRecords, $eventsMetaData) = getRecords(array(
    'tableName'   => 'events',
    'loadUploads' => true,
    'allowSearch' => false,
  ));

  // load records from 'press_releases'
  list($press_releasesRecords, $press_releasesMetaData) = getRecords(array(
    'tableName'   => 'press_releases',
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '2',
  ));

But as you can see, I'm loading 2 times my press_releases records (one for the index content page) and the other one for my footer content... or what's the best way to display all my press releases on the index and just a 2 limit on my footer on cases like this?

I hope I'm explaining this properly, thanks in advance for your help!

Jesus

By ht1080z - November 3, 2013 - edited: November 3, 2013

Hi Jesus,

You need to call the section with different names on the same page, example:

  // load records from 'press_releases'
  // for the main section of the page

  list($all_press_releasesRecords, $all_press_releasesMetaData) = getRecords(array(
    'tableName'   => 'press_releases',
    'loadUploads' => true,
    'allowSearch' => false,
  ));

  // load records from 'press_releases'
  // for the footer section of the page

  list($press_releasesRecords, $press_releasesMetaData) = getRecords(array(
    'tableName'   => 'press_releases',
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '2',
  ));

Remember, you can name each query as you like and call as many times you want in the same page, but you need to change the array names for each. Example, the third one for the sidebar...

  // load records from 'press_releases'
  // additional records for the sidebar (the 5 latest post)

  list($sidePressRecords, $sidePressMetaData) = getRecords(array(
    'tableName'   => 'press_releases',
    'loadUploads' => true,
    'allowSearch' => false,
    'orderBy'     => "date DESC",
    'limit'       => '5',
  ));

and create the print out for the array depending on the array name like:

foreach($sidePressRecords as $sidePress) {
    echo $sidePress['title'];
}

I hope this will help,
Karls