Re: Re: [design9] Excluding certain content/list

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

By design9 - March 26, 2013

In response to: [url "http://www.interactivetools.com/forum/forum-posts.php?postNum=2217839#post2217839"]Re: [design9] Excluding certain content/list[/url], ...

The coding here from previous post works great , it pulls only the blogs in that are NOT in the Daily Post or Parenting Tip of the week but the issue is that it still counts these blogs that are excluded in the total (3 most recent blogs to show).  I would like the total to still show the 3 most recent blogs but not count the daily post or parenting tip in the count.  Is there a way to accomplish this?

Current Code:

<?php foreach ($blogsRecords as $blogs):
//This if statement will skip a loop if the daily post is found in the related header label.
if(in_array("The Daily Post", $blogs['header:labels']) || in_array("Parenting Tip of the Week", $blogs['header:labels']) ){ continue;}

?>
<?php

$num = $blogs['header']; 

list($header_images_smallRecords, $header_images_smallMetaData) = getRecords(array( 
'tableName' => 'header_images_small', 
'where' => "num ='$num'", 

)); 
?> 

<?php if($count>3){$count=1;} ?>

<?php $count=3;?> 
<div class="tabs-innerlft">
<?php foreach ($header_images_smallRecords as $header_image): ?>


<?php foreach ($header_image['image'] as $upload): ?>
<?php if ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" title="<?php echo $upload['info1'] ?>" class="image" /><br/>


<?php endif ?>
<?php endforeach ?></div>
<?php endforeach ?> 
<div class="tabs-innerrgt"> 
<h3><a href="<?php echo $blogs['_link'] ?>"><span class="articlehead"><?php echo $blogs['title'] ?></span></a></h3>
<p><?php echo preg_replace("/<img[^>]+\>/i", "", maxWords($blogs['content'], 37)); ?>...<a href="<?php echo $blogs['_link']; ?>">More</a> </p></div>
<?php endforeach; ?>

Thank you,

April

Hi April,

Using your current code, this would be the simplest method:

<?php $counter = 1; ?>
<?php foreach ($blogsRecords as $blogs):
  //This if statement will skip a loop if the daily post is found in the related header label.
  if(in_array("The Daily Post", $blogs['header:labels']) || in_array("Parenting Tip of the Week", $blogs['header:labels']) ){ continue;}
  //If three articles have been displayed, exit out of the loop.
  if($counter > 3){ break; }

  ?>
  <?php

  $num = $blogs['header']; 

  list($header_images_smallRecords, $header_images_smallMetaData) = getRecords(array( 
  'tableName' => 'header_images_small', 
  'where' => "num ='$num'", 

  )); 
  ?> 

  <?php if($count>3){$count=1;} ?>

  <?php $count=3;?> 
  <div class="tabs-innerlft">
  <?php foreach ($header_images_smallRecords as $header_image): ?>


    <?php foreach ($header_image['image'] as $upload): ?>
      <?php if ($upload['isImage']): ?>
      <img src="<?php echo $upload['urlPath'] ?>" title="<?php echo $upload['info1'] ?>" class="image" /><br/>


      <?php endif ?>
    <?php endforeach ?></div>
  <?php endforeach ?> 
  <div class="tabs-innerrgt"> 
  <h3><a href="<?php echo $blogs['_link'] ?>"><span class="articlehead"><?php echo $blogs['title'] ?></span></a></h3>
  <p><?php echo preg_replace("/<img[^>]+\>/i", "", maxWords($blogs['content'], 37)); ?>...<a href="<?php echo $blogs['_link']; ?>">More</a> </p></div>
  <!-- increase the counter value by 1 -->
  <?php $counter++; ?>
<?php endforeach; ?>

So I've added a counter that's value increases by one every time an about article is successfully displayed. When three articles are successfully displayed the counter will be equal to 4, and the if statement at the top will break out of the loop and stop it displaying anything else in the array. 

You will also need to edit this limit from your getRecords function for the about section:

 list($aboutRecords, $aboutMetaData) = getRecords(array(
   'tableName'   => 'about',
   'limit'         => '5',
 ));  
  

This will make the getRecords function retrieve the first 5 records, as it might not display 2 of them, leaving 3 that that it can always display. 

Let me know if you have any questions

Thanks

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By design9 - April 2, 2013

Greg,

Thank you for your help.

I added the code but it is still not working. It still counts the Daily Post and Parenting Tip of the Week in the total. Is there anything else I can do so it skips any posts with those categories in the count?

Thanks!

April

By design9 - April 4, 2013

Sure, Here it is.

Thanks!

April

Attachments:

newindex.php 30K

By gregThomas - April 4, 2013

Hi April,

I think it might be that you need to change the break level to 2:

<?php $counter = 1; ?>
<?php foreach ($blogsRecords as $blogs):
  //This if statement will skip a loop if the daily post is found in the related header label.
  if(in_array("The Daily Post", $blogs['header:labels']) || in_array("Parenting Tip of the Week", $blogs['header:labels']) ){ continue;}
  //If three articles have been displayed, exit out of the loop.
  if($counter > 3){ break 2; }

  ?>
  <?php

  $num = $blogs['header']; 

  list($header_images_smallRecords, $header_images_smallMetaData) = getRecords(array( 
  'tableName' => 'header_images_small', 
  'where' => "num ='$num'", 

  )); 
  ?> 

  <?php if($count>3){$count=1;} ?>

  <?php $count=3;?> 
  <div class="tabs-innerlft">
  <?php foreach ($header_images_smallRecords as $header_image): ?>


    <?php foreach ($header_image['image'] as $upload): ?>
      <?php if ($upload['isImage']): ?>
      <img src="<?php echo $upload['urlPath'] ?>" title="<?php echo $upload['info1'] ?>" class="image" /><br/>


      <?php endif ?>
    <?php endforeach ?></div>
  <?php endforeach ?> 
  <div class="tabs-innerrgt"> 
  <h3><a href="<?php echo $blogs['_link'] ?>"><span class="articlehead"><?php echo $blogs['title'] ?></span></a></h3>
  <p><?php echo preg_replace("/<img[^>]+\>/i", "", maxWords($blogs['content'], 37)); ?>...<a href="<?php echo $blogs['_link']; ?>">More</a> </p></div>
  <!-- increase the counter value by 1 -->
  <?php $counter++; ?>
<?php endforeach; ?>

If this doesn't work, could you fill out a second level support request for me? You can find the form here:

https://www.interactivetools.com/support/email_support_form.php

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com