displaying alternate content if no record in category

5 posts by 3 authors in: Forums > CMS Builder
Last Post: July 9, 2009   (RSS)

Re: [Deborah] displaying alternate content if no record in category

By ross - July 9, 2009

Hi Deborah

Thanks for posting!

Could you try this if block instead of the one you are using:

<?php

if (!count($record)) {
echo "there were no categories";
}

?>


Leave the foreach loop as is. Just replace your if block with this one and let me know how you make out.

Thanks!
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [Deborah] displaying alternate content if no record in category

By Damon - July 9, 2009

Hi Deborah,

Here is another option for you using Tech, Sports and Lifestyle as categories. With each category, you can have a custom message if there is no content for that category.

<!-- Tech starts -->
<h2>Category: Tech</h2>
<?php
$count = 0;
foreach ($newsRecords as $record):
if ($record['category'] != "tech") { continue; }
$count++;
?>
Title: <?php echo $record['title'] ?><br/>
<?php endforeach; ?>

<?php if (!$count): ?>
No tech content
<?php endif; ?>


<!-- Sports starts -->

<h2>Category: Sports</h2>
<?php
$count = 0;
foreach ($newsRecords as $record):
if ($record['category'] != "sports") { continue; }
$count++;
?>
Title: <?php echo $record['title'] ?><br/>
<?php endforeach; ?>

<?php if (!$count): ?>
No sports content
<?php endif; ?>


<!-- LifeStyle starts -->

<h2>Category: Lifestyle</h2>
<?php
$count = 0;
foreach ($newsRecords as $record):
if ($record['category'] != "lifestyle") { continue; }
$count++;
?>
Title: <?php echo $record['title'] ?><br/>
<?php endforeach; ?>

<?php if (!$count): ?>
No lifestyle content
<?php endif; ?>


Let me know how this works for you.
Cheers,
Damon Edis - interactivetools.com

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

Re: [ross] displaying alternate content if no record in category

By Deborah - July 9, 2009 - edited: July 9, 2009

Hi, Ross. Thank you for the post! I wasn't successful with editing the code. I probably did not understand fully... my error, no doubt. Here's the code I used:

[font "Verdana"]<?php foreach ($links_resourcesRecords as $record): ?>
<?php if ($record['category'] != "Electrical") { continue; } ?>
<p><?php echo $record['name'] ?></p>
<?php endif ?>
[font "Verdana"]<?php endforeach; ?>
<?php if (!count($record)) { echo "there were no categories"; } ?>
<p>No listings at this time.</p>
<?php endif ?>


Error message: Parse error: syntax error, unexpected T_ENDIF

[font "Verdana"]I solved what I needed to do by utilizing Damon's suggestion that followed yours. Sorry I couldn't make this work, but appreciate the help very much.

[font "Verdana"]Deborah

Re: [Damon] displaying alternate content if no record in category

By Deborah - July 9, 2009

Damon,

That worked perfectly. I like the added ability to include a unique message for each of the categories! Thank you so much for your assistance.

Deborah