News section categories record display on different page.

12 posts by 3 authors in: Forums > CMS Builder
Last Post: April 23, 2013   (RSS)

By esupport - April 18, 2013

Hi 

I created a News section.  There are 3 categories for this section.

1) News Press
2) Announcements
3) Conferences

That is no problem to display 3 categories on one page.

But I also want the 3 different news category display on it own page. also I can sort it.

How to do it?

Here is my code for the news section.

<?php foreach ($news_1Records as $record): ?>
Record Number: <?php echo htmlencode($record['num']) ?><br/>
date: <?php echo date("D, M jS, Y g:i:s a", strtotime($record['date'])) ?><br/><!-- For date formatting codes see: http://www.php.net/date -->
category (value): <?php echo $record['category'] ?><br/>
category (label): <?php echo $record['category:label'] ?><br/>
Title: <?php echo htmlencode($record['title']) ?><br/>
Content: <?php echo $record['content']; ?><br/>
_link : <a href="<?php echo $record['_link'] ?>"><?php echo $record['_link'] ?></a><br/>
<hr/>
<?php endforeach ?>

Thanks a lot!

Jac

-Jax H.

By gkornbluth - April 18, 2013 - edited: April 18, 2013

Hi Jac,

For the Announcements category you could try a where statement in the list records call for the Announcement viewer

'where' => " category = 'Announcements' "

Or you could try an if statement inside the foreach loop:

<?php foreach ($news_1Records as $record): ?>

<?php if($record['category'] == 'Announcements') : ?>


The rest of your code...


<?php endif ?>


<?php endforeach ?>

Then change the criteria for the other viewers as appropriate

Hope that helps you,

Gerald Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Hi Jac,

Just thought I'd extend on Jerrys answer by adding that you can sort the items by the category name in your getRecords array like this:

  // load records from 'blog'
  list($($news_1Records, $($news_1RecordsMetaData) = getRecords(array(
    'tableName'   => 'blog',
    'loadUploads' => true,
    'allowSearch' => false,
    'orderBy'     => 'category ASC'
  ));

You should just need to copy the green orderBy item above and add it to your getRecords array.

This will make it so that the returned items will be sorted by the category field in alphabetical order.

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By esupport - April 18, 2013

HI Gerald and Greg

Trying now.

Thanks a lot!

Jac

-Jax H.

By esupport - April 21, 2013

Hi Gerg

It is nice and no problem for List page record.    

But got problem with getting announcements on Detail page.

I have created announcementsList.php & announcementsDetail.php page now.

Here is my code now(List page):

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?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('/home/httpd/vhosts/kwbs.org.tw/httpdocs/web/','','../','../../','../../../');
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 records from 'news'
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'where' => "category = 'announcements'",
'loadUploads' => true,
'allowSearch' => false,
'orderBy' => 'category ASC'
));
?>

Body

<table width="85%" border="0" align="center" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td width="70%" align="left" class="line_h_double_brown_bottom"><img hspace="10"
alt="Latest News" vspace="7"
src="images/index/title_news.gif"
width="97" height="14" /></td>
<td width="30%" align="right" valign="bottom" class="line_h_double_brown_bottom"><a href="index.html"><img
class="banner_line_no" hspace="5" alt="More News!" vspace="9"
src="images/share/button_more.gif" /></a></td>
</tr>
<tr>
<td valign="top" colspan="2" align="right">
<?php foreach ($newsRecords as $record): ?>
<div>
<ul>
<li><?php echo date("Y-m-d", strtotime($record['date'])) ?> | <a href="<?php echo $record['_link'] ?>"><?php echo htmlencode($record['title']) ?></a></li>
</ul>
</div>
<?php endforeach ?>
<?php if (!$newsRecords): ?>
No records were found!
<?php endif ?>
<hr /></td>
</tr>
</tbody>
</table>

need help!

Thanks a lot!

Jac 

-Jax H.

By esupport - April 22, 2013

Hi Jerry

I found the solution.  

but got problem in "<< Back to list page" &  "Email this Page"

My Header code

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?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('/home/httpd/vhosts/kwbs.org.tw/httpdocs/web/','','../','../../','../../../');
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 'news'
list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'where' => "category = 'announcements'",
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$newsRecord = @$newsRecords[0]; // get first record
if (!$newsRecord) { dieWith404("Record not found!"); } // show error message if no record found

?>

Body code

<h1>Detail Page Viewer</h1>
category (value): <?php echo $newsRecord['category'] ?><br/>
Title: <?php echo htmlencode($newsRecord['title']) ?><br/>
Content: <?php echo $newsRecord['content']; ?><br/>

<hr/>

<a href="<?php echo $newsMetaData['_listPage'] ?>">&lt;&lt; Back to list page</a> <a href="mailto:?subject=<?php echo urlencode(thisPageUrl()) ?>">Email this Page</a></td>

Thanks in advance for your help.

Jac.

-Jax H.

By esupport - April 22, 2013

Hi Gerald

I created a News section.  There are 3 categories for this section.

1) News Press
2) Announcements
3) Conferences

I add the code on page Header to get the Announcements record.

'where' => " category = 'Announcements' "

and there are 2 pages "announcementsList.php" & "announcementsDetail.php"

Now I got problem in "_link".  How can I get correct detail page to link in

_link : <a href="<?php echo $record['_link'] ?>"><?php echo $record['_link'] ?></a><br/>

also How can I get the correct "Back to list page" , "Email this page" URL?

<a href="<?php echo $newsMetaData['_listPage'] ?>">&lt;&lt; Back to list page</a> <a href="mailto:?subject=<?php echo urlencode(thisPageUrl()) ?>">Email this Page</a></td>

Now all get errors.

Thanks a lot for the help!

Jac

-Jax H.

Hi Jac

You can set the list page and detail page URL's in the CMS admin area. If you go the the section editors menu, then click the modify link on the section you want to edit, then go to the viewer URLs tab, you can set which list and detail page URL's you want. These will then be stored in the sections meta data and _link field.

What is the issue you're having with the e-mail this page link? I did a quick test and it seemed to work correctly for me. 

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By esupport - April 22, 2013

Hi Gerg

One problem is 

There are 3 news categories on the NEWS section.

The section only can set one URL  -  newsList.php and newsDetail.php.

When I generate the code page for Announcement page.  It will go to newslist.php

I would like to create 

"AnnouncementsList.php" & "AnnouncementsDetail.php" to display the Announcements news only.

"ConferencesList.php" & "ConferencesDetail.php"  to display the Conferences news only.

It all belong to NEWS section.

The attachment is the news categories code.

Hope you can understand the meaning.

Could you kindly help this?

Thanks a lot!

Jac

-Jax H.