Navigation breaking

10 posts by 3 authors in: Forums > CMS Builder
Last Post: August 13, 2012   (RSS)

Hi,

I'm using some code that I've used before (and it worked) to create my navigation. Within this code, I wanted to exclude any that had 1 in the is_feature field.

However, when I put the code in like:

<?php foreach ($allIndex_homeRecords as $categoryRecord): ?>
<?php if(!$categoryRecord['is_feature']): ?>
<?php echo $categoryRecord['_listItemStart']; ?>
<span <?php if($thisPage == "index"){echo 'class="currentpage"';} ?>><a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a></span>
<?php echo $categoryRecord['_listItemEnd'] ?>
<?php endif; ?>
<?php endforeach; ?>

It breaks the navigation (please find attached how_nav_is_breaking.png and how_nav_is_breaking_source.html).

If i put the code in like:

<?php foreach ($allIndex_homeRecords as $categoryRecord): ?>
<?php echo $categoryRecord['_listItemStart']; ?>
<span <?php if($thisPage == "index"){echo 'class="currentpage"';} ?>><a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a></span>
<?php echo $categoryRecord['_listItemEnd'] ?>
<?php endforeach; ?>

The navigation is as it should be (please find attached how_nav_should_be.png and how_nav_should_be_source.html), but the navigation displays the 'features', when it shouldn't.

So you can understand more, if you go to: http://jubileehighschool.no-ip.org/curriculum.php?Curriculum-1-1, you will see two blocks on the right (feature and feature2), now if you hover over Curriculum 1 in the nav, you will also see feature and feature 2 there, but I don't want them to be displayed in the nav.

Re: [dsternalski] Navigation breaking

Hi dsternalski,

Do you have 'allowSearch' => false, in your get records call?

Jerry 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

Re: [gkornbluth] Navigation breaking

Hi,

Yes I have in the getRecords call but not in the getCategories call.

Re: [dsternalski] Navigation breaking

By Jason - August 8, 2012

Hi,

The issue here is that in your first foreach loop, you're not outputting all your records. You're only outputting records where "is_feature" is selected. You probably need an "else" for outputting records where that is not set.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

Re: [Jason] Navigation breaking

Hi,

In the first for each loop, I have an ! (explanation mark) before the variable as I'm trying to output all records except those that have is_feature = 1.

Re: [dsternalski] Navigation breaking

By Jason - August 8, 2012

Hi,

You're right, I misread that.

getCategories creates the listItemStart and listItemEnd pseudo fields that contain all the <ul> and <li> tags to produce a nested list. When you filter out some records, it's throwing these tags off, so certain records are being nested when they shouldn't be. Currently, there isn't a good way to filter category records using a field value.

One option would be to output all records. If a record is featured and you don't want to display it, you could add CSS to it's <a> tag to set display to none. That way it doesn't show up, but the nesting stays correct.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

Re: [Jason] Navigation breaking

Hi,

I will give that a try, but I have a feeling that although it will hide the <a> tag, that it won't hide the <li> tag, leaving a slight height in the empty <li>.

I have used code like this before to hide features in the navigation & it worked fine in an older version of the CMS, so I'm wondering if possibly where the code behind the CMS has been updated that it now doesn't work.

Re: [Jason] Navigation breaking

By dsternalski - August 11, 2012 - edited: August 11, 2012

I already have a 'hidden' checkbox, and I can't really use this not to display hidden as this will affect other pages.

I have tried this:

<?php foreach ($allIndex_homeRecords as $categoryRecord): ?>
<?php echo $categoryRecord['_listItemStart']; ?>
<?php if(!$categoryRecord['is_feature']): ?>
<span <?php if($thisPage == "index"){echo 'class="currentpage"';} ?>><a href="<?php echo $categoryRecord['_link']; ?>"><?php echo $categoryRecord['name']; ?></a></span>
<?php endif; ?>
<?php echo $categoryRecord['_listItemEnd']; ?>
<?php endforeach; ?>

And although it doesn't break the navigation, it doesn't completely remove the empty <li>'s.

Attached is an image of what I mean.
Attachments:

empty-li.png 67K

Re: [dsternalski] Navigation breaking

By Jason - August 13, 2012

Hi,

Another option is to get the display:none style into the li/ul tags

First add this function to your page:

function hideFeaturedCategories($category) {

if ($category['is_featured']) {
return "style = 'display:none'";
}

return;
}



Then you can call this function using the li and ul attributes callback options in getCategories

EXAMPLE:

'liAttributesCallback' => 'hideFeaturedCategories',
'ulAttributesCallback' => 'hideFeaturedCategories',


Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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