mixed feeds?

11 posts by 3 authors in: Forums > CMS Builder
Last Post: February 27, 2014   (RSS)

By osga - February 18, 2014

We are working on a Contributing Writers area and would like it to be 1 art summary(the latest art) and 2 subsequent headlines...?

like this...
http://www.osga.com/writer_zone.html

Hi Osga,

What's the exact issue you're having with creating this layout? How are your sections set up? Do you have a writers section that is linking the news/articles section via a list field, or is all this information available in each record in the same section? 

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By osga - February 19, 2014

well we have a single summary feed made, an a headlines only feed that we could just put in the page together for each writer, but the real prob we have then, is the headlines had the same #1 art in it as the top summary article:


Headline 1
summary

headline 1 (again)

headline 2

headline 3

what we want is:

Headline 1
summary

headline 2

headline 3

By Dave - February 20, 2014

Hi osga, 

So basically you just need to be able to check if a record is the first one?  Let me know if something like this would work for you:

<?php foreach ($newsRecords as $record): ?>
  <?php $isFirst = ($record == reset($newsRecords )); ?>

  Record Number: <?php echo htmlencode($record['num']) ?><br/>
  Title: <?php echo htmlencode($record['title']) ?><br/>

  <?php if ($isFirst): ?> <b>This is the first record</b> <?php endif ?>
  <hr/>
<?php endforeach ?>

We're checking if the record is the first one in the list and setting $isFirst with a true/false value, then checking $isFirst later in the code to display something for the first record only.

Let me know if that works for you (be sure to change $newsRecords to the variable name that has your records in it).

Dave Edis - Senior Developer
interactivetools.com

By osga - February 21, 2014

getting closer, but still seeing the first record... sry, we're not php people here. lol.

here's what we have so far....

http://www.osga.com/singleart_cms_writers.php

just need to eliminate the 1st art headline and we are go to go!

By Dave - February 21, 2014

Hi osga, 

Can you post the foreach/endforeach code snippet that generates that? Then I can take a look and offer some suggestions.

Also, I'll note that this is above and beyond what CMSB does, it's just using PHP to format a list of things, so it can get a bit tricky, but we'll try to help.

Let me know, thanks!

Dave Edis - Senior Developer
interactivetools.com

By osga - February 21, 2014


    <?php foreach ($articlesRecords as $record): ?>
 
     <span style="font-size:14px"><b>  <?php echo $record['title'] ?></b></span><br/>
     <span style="font-size:12px"> <?php echo $record['summary'] ?><br/>
       <a href="<?php echo $record['_link'] ?>" target="_new"><b>Read More Here...</b></a><br/>
        <?php foreach ($record['images'] as $upload): ?>
          <?php if ($upload['hasThumbnail']): ?>
            <img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><br/>

          <?php elseif ($upload['isImage']): ?>
            <img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>


          <?php endif ?>
        <?php endforeach ?>

By Dave - February 21, 2014

Hi osga, 

I think your code got clipped at the bottom there, but what about something like this:

<?php foreach ($articlesRecords as $record): ?>
  <?php $isFirst = ($record == reset($newsRecords )); ?>
  
  <?php if ($isFirst): // if first record ?>
    <span style="font-size:14px"><b>  <?php echo $record['title'] ?></b></span><br/>
    <span style="font-size:12px"> <?php echo $record['summary'] ?><br/>
    <a href="<?php echo $record['_link'] ?>" target="_new"><b>Read More Here...</b></a><br/>
    <?php foreach ($record['images'] as $upload): ?>
      <img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><br/>
    <?php endforeach ?>
  <?php endif ?>
  
  <?php if (!$isFirst): // is 2nd, 3rd, etc ecord ?>
    <span style="font-size:14px"><b>  <?php echo $record['title'] ?></b></span><br/>
    <span style="font-size:12px"> <?php echo $record['summary'] ?><br/>  
  <?php endif ?>
  
<?php endforeach ?>

Basically we're checking $isFirst to show one block of HTML for the first record, and something else for all the others.

If that doesn't do it upload your page as an attachment to this thread and provide us some more details.  Sometimes it can be hard to explain but we need to "get" what's going on to help.

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com

Hi Osga, 

I've made a few changes to your code, if replace everything in your file after line 62 with the following:

<?php
  // load records
  list($articlesRecords, $articlesMetaData) = getRecords(array(
    'tableName'   => 'articles',
    'limit'       => '3',
  ));

?>
  <?php foreach ( $articlesRecords as $record): ?>
    <?php $isFirst = ($record == reset($articlesRecords )); ?>
    <?php if (!$isFirst):?> 
      <a href="<?php echo $record['_link'] ?>" target="_new"><?php echo htmlencode($record['title']) ?></b></a><br/><br />
    <?php endif ?>  
  <?php endforeach ?>
      <!-- STEP2a: /Display Uploads -->


    <?php endforeach ?>

    <?php if (!$articlesRecords): ?>
      No records were found!<br/><br/>
    <?php endif ?>
  <!-- /STEP2: Display Records -->
    

</td></tr></table>

You should find that the records are loaded correctly.

Here is a break down of the issues I've resolved:

  • The page added a text/html header twice, this can stop the page loading on some servers as they've already started creating the page. The header would normally be the first thing appears on a PHP page. 
  • The page had an include for the viewer libraries twice, you only need to call these once for each page, usually at the top of the page.
  • The page was missing the ! in the if statement (highlighted in red) for the first record. This is a used in an if statement as a not eg, "if not the first record, then do X".
  • The page had the link outside of the if statement, it needed to inside of it.

Let me know if this doesn't work, or if you have any issues.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com