Featured story/top news items

6 posts by 3 authors in: Forums > CMS Builder
Last Post: September 29, 2015   (RSS)

By rlindauer - September 18, 2015

I'm trying to set up my homepage so it has 3 top stories or news items. The first one has a layout of it's own with a larger photo, then the other two stories appear below it. You can see the layout here:

http://www.polkcountynewspaper.com/new2/index.php

I already added "feature_1, feature_2, feature_3" as a new field in the Section Editor area, but I'm not great at the code and fields. How do I tell it to place feature_1 in the top position (if the box is checked for that story) and then feature_2 goes in the next slot, etc?

I figured it's probably if "feature_1" is checked, then display the story.

If feature_2 is checked, then put that story here... etc. But I don't know how to write that snippet of code.

Your help would be greatly appreciated! Thanks!!

By Daryl - September 23, 2015

Hi rlindauer,

I figured it's probably if "feature_1" is checked, then display the story.

- Yes, that is one of many ways to do it. You need to loop through the news records until you find the record with featured_* checked, and then display the record. But you'll need to do the loop 2 or 3 times.
For example:

<!--For the 1st featured news-->
<?php
foreach ($newsRecords as $record){
  if (!$record['featured_1']) { continue; } // continue looping if featured_1 is not checked
  ?>
  your html code here + record's contents
  <?php
}
?>

<!--For the next 2 featured news-->
<?php
foreach ($newsRecords as $record){
  if (!$record['featured_2'] AND !$record['featured_3']) { continue; }
  ?>
  your html code here + record's contents
  <?php
}
?>

Hope that helps!

Cheers,

Daryl Maximo
PHP Programmer - interactivetools.com

By rlindauer - September 24, 2015

Thanks for your help! We're on the right track! Except now I'm getting 4 copies of the 1st feature story, but nothing from the second and third stories. 

You can see the page here:

http://www.polkcountynewspaper.com/new2/index_FEATURE.php

My code is attached.

I also want to make sure the feature stories are not JUST from our NEWS section. The feature stories might come from the sports section from time to time. Is it possible to just leave it open so that ANY story marked "feature_1", "feature_2" or "feature_3" gets placed on the homepage (no matter which section it comes from)?

Attachments:

FeatureStories.rtf 3K

By Damon - September 25, 2015

Hi,

I took a look at the code and made some changes. Having multiple check-boxes is problematic in that you can check more than one and you can't easily view what article is featured from within the CMS Builder admin.

A better approach is to create a Featured dropdown list with the following options:
feature_1
feature_2
feature_3

Next, add featured to the ListPage Fields in Admin > Section Editors > News. See attached image.

This will show the featured column.

Use this code. Modify as needed:

<!--BEGIN 1st FEATURE STORY-->
<?php foreach ($newsRecords as $record): ?>
<?php if ($record['featured'] != "feature_1") { continue; } // continue looping if featured_1 is not selected ?>
<?php foreach ($record['image'] as $index => $upload): ?>
<?php if ($index >= 1) { continue; } // limit uploads shown ?>
<img src="<?php echo htmlencode($upload['thumbUrlPath']) ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" style="float: left; padding: 20px 10px 20px 0;"/><br/>
<?php endforeach ?>
<strong><?php echo htmlencode($record['title']) ?></strong><br/>
<?php echo date("M jS, Y", strtotime($record['date'])) ?><br/>
<?php echo htmlencode($record['summary']) ?><br/>
<a href="<?php echo $record['_link'] ?>"><?php echo $record['_link'] ?></a><br/>
<?php break; ?>
<?php endforeach ?>
<br clear="left" />
<!--END 1st FEATURE STORY-->


<!--BEGIN 2nd FEATURE STORY-->
<?php foreach ($newsRecords as $record): ?>
<?php if ($record['featured'] != "feature_2") { continue; } // continue looping if featured_2 is not selected ?>
<?php foreach ($record['image'] as $index => $upload): ?>
<?php if ($index >= 1) { continue; } // limit uploads shown ?>
<img src="<?php echo htmlencode($upload['thumbUrlPath']) ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" style="float: left; padding: 20px 10px 20px 0;"/><br/>
<?php endforeach ?>
<strong><?php echo htmlencode($record['title']) ?></strong><br/>
<?php echo date("M jS, Y", strtotime($record['date'])) ?><br/>
<?php echo htmlencode($record['summary']) ?><br/>
<a href="<?php echo $record['_link'] ?>"><?php echo $record['_link'] ?></a><br/>
<?php break; ?>
<?php endforeach ?>
<!--END 2nd FEATURE STORY-->



<!--BEGIN 3rd FEATURE STORY-->
<?php foreach ($newsRecords as $record): ?>
<?php if ($record['featured'] != "feature_3") { continue; } // continue looping if featured_3 is not selected ?>
<?php foreach ($record['image'] as $index => $upload): ?>
<?php if ($index >= 1) { continue; } // limit uploads shown ?>
<img src="<?php echo htmlencode($upload['thumbUrlPath']) ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" style="float: left; padding: 20px 10px 20px 0;"/><br/>
<?php endforeach ?>
<strong><?php echo htmlencode($record['title']) ?></strong><br/>
<?php echo date("M jS, Y", strtotime($record['date'])) ?><br/>
<?php echo htmlencode($record['summary']) ?><br/>
<a href="<?php echo $record['_link'] ?>"><?php echo $record['_link'] ?></a><br/>
<?php break; ?>
<?php endforeach ?>
<!--END 3rd FEATURE STORY-->

Let me know how this works out and if you have any questions.

Cheers,
Damon Edis - interactivetools.com

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

By rlindauer - September 25, 2015

We're almost there! Things are working great with a few minor adjustments in the code you sent. Now the only part I can't figure out is why I'm getting the same image for all 3 featured stories. It's the image from "feature 1" all 3 times.