4 posts by 2 authors in: Forums > CMS Builder
Last Post: April 14, 2014   (RSS)

By Deborah - April 2, 2014

I've searched the form, but am not able to find this topic. What I'm trying to achieve is:

  1. If the URL to the list page viewer contains a category num, I would like the page heading on the list viewer page to display 'CategoryName News'.
  2. If the URL does not contain a category num, I'd like the page heading to display just 'News'.

What's happening with my current code is that if there is not a category num in the URL, the page displays the last updated category title instead of nothing.


A) Display news articles filtered by category in URL:
<a href="/news/index.php/category-<?php echo ($record['num']) ?>/">
(Shows selected page title category, as intended.)

B) Display all news articles:
<a href="/news/index.php">
(Shows a page title even if no category is in URL.)


---- HEAD ----
// 'news' list
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'orderBy' => "posting_date DESC",
// category title for pg heading
list($newsRecordsHDG, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'limit' => '1',
'where' => whereRecordNumberInUrl(1),
'allowSearch' => true, // also tried as false

---- HTML ----
<?php if ($newsRecordsHDG): ?>
<?php foreach ($newsRecordsHDG as $record): ?><?php echo $record['category:label'] ?><?php endforeach ?>
<?php endif ?> News

Desired HTML output:

If category num in URL = 'Category News'

If no category num in URL = 'News'

I hope I've explained myself well enough. Thanks for looking and especially for any help!
~ Deborah

By Chris - April 3, 2014

Hi Deborah,

The argument to whereRecordNumberInUrl() is the default where clause used if there is no number in the URL. whereRecordNumberInUrl(1) is the same as whereRecordNumberInUrl("TRUE"), it defaults to WHERE TRUE, so it will find the first record.

whereRecordNumberInUrl("FALSE") or whereRecordNumberInUrl(0) will not return a record if there is no number in the URL.

This should work:

---- HEAD ----
// 'news' list 
list($newsRecords, $newsMetaData) = getRecords(array( 
  'tableName' => 'news', 
  'orderBy' => "posting_date DESC", 
// category title for pg heading 
list($newsRecordsHDG, $newsMetaData) = getRecords(array( 
  'tableName' => 'news', 
  'limit' => '1', 
  'where' => whereRecordNumberInUrl("FALSE"), // if no record number in url, where = FALSE
  'allowSearch' => false,

---- HTML ----
<?php if ($newsRecordsHDG): ?>
  <?php foreach ($newsRecordsHDG as $record): ?><?php echo $record['category:label'] ?><?php endforeach ?>
<?php else: ?>
<?php endif ?>

Does that help?

All the best,

By Chris - April 14, 2014

Hi Deborah,

Glad to be of help!

All the best,