If statement to style navigation/current page

20 posts by 3 authors in: Forums > CMS Builder
Last Post: June 15, 2009   (RSS)

By Kittybiccy - April 7, 2009

I'm trying to work out a way of styling some navigation so that when the viewer is on a pagel, the page in the navigation displays in a colour.

The breadcrumb navigation is built to display titles of sections on certain pages - Ross helped me code this - but because these are not part of the HTML and are generated by the CMSB, I'm not sure how to get what I need.

The code I'm using is like this:
<?php foreach ($naptonRecords as $naptonRecord): ?>
<?php echo $naptonRecord['_listItemStart'] ?>

<?php ?>
<?php if ($naptonRecord['linkOverride']): ?>
<a href="<?php echo $naptonRecord['linkOverride'] ?>">
<?php else: ?>
<a href="<?php echo $naptonRecord['_link'] ?>">
<?php endif ?>

<?php ?>
&nbsp;&nbsp; <?php echo $naptonRecord['title'] ?></a>

<?php echo $naptonRecord['_listItemEnd'] ?>
<?php endforeach; ?>

Anyone know of an If statement or something I can add so that the current page displays in a colour?

Any help/ideas/suggestions would be brilliant!
Hannah

Re: [Kittybiccy] If statement to style navigation/current page

By ross - April 7, 2009

Hi Hannah

I think what you are going to be looking for here is the _isSelected option. You can do tests on it like this:

<?php if ($naptonRecord['_isSelected']): ?>
<b>
<?php endif; ?>


You might need to play with that a bit to get the right effect.

Let me know what you think.
-----------------------------------------------------------
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: [ross] If statement to style navigation/current page

By Kittybiccy - April 8, 2009

Thanks Ross!

Where would this sort of thing need to go? I've tried putting it at difference places within the breadcrumb code but get different errors everytime like undefined variables etc! Should it specifically go within a part of the code that is working?

Hannah

Re: [Kittybiccy] If statement to style navigation/current page

By ross - April 9, 2009

Hi Hannah

That code would need to go right before where you display the category name.

<?php if ($naptonRecord['_isSelected']): ?>
<b>
<?php endif; ?>
CATEGORY NAME
</b>


Make sure to put in that </b> after your category name or everything will go bold :).
-----------------------------------------------------------
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: [ross] If statement to style navigation/current page

By Kittybiccy - May 8, 2009

Hi Ross,

I have been using the code to style the 'current' page and it is all working well except for (again) when you get to those difficult team list pages and the detail page. Is there something I will need to tweak here?

This is the code to style the menu:
<div id="menu"><ul>
<li>
<?php foreach ($church_endRecords as $church_endRecord): ?>
<?php echo $church_endRecord['_listItemStart'] ?>
<?php ?>
<?php if ($church_endRecord['linkOverride']): ?>
<a href="<?php echo $church_endRecord['linkOverride'] ?>">
<?php else: ?>
<a href="<?php echo $church_endRecord['_link'] ?>">
<?php endif ?>
<?php if ($church_endRecord['_isSelected']): ?>
<span class="current">
<?php endif; ?>
<?php ?>
&nbsp;&nbsp; <?php echo $church_endRecord['title'] ?></a></span>


<?php echo $church_endRecord['_listItemEnd'] ?>
<?php endforeach; ?>
</ul>
</li> </div>

I will attach the page it's not working on, would be really really helpful if someone could have a look for me! This is what it is supposed to be doing:
http://www.arcschoolsuk.com/CMSB/church_end.php?5

Thanks in advance!
Attachments:

church_end_teamlist.php 8K

Re: [Kittybiccy] If statement to style navigation/current page

By rebjr - May 8, 2009

Have you considered doing this with CSS? It is much easier than trying to do it via CMS Builder and/or PHP. Here's an article that explains the basics:

http://hicksdesign.co.uk/journal/highlighting-current-page-with-css

Rob

Re: [rebjr] If statement to style navigation/current page

By Kittybiccy - May 11, 2009

The navigation is controlled by the CMS Builder so that the client can add pages which will be included in the navigation and not have to come back to me at any point. I'm not sure that there is another 'easy' way that I could do this! But let me know if you think there is.

Re: [Kittybiccy] If statement to style navigation/current page

By ross - May 18, 2009

Hi there.

I didn't actually notice your last post was a question. I thought you had it all figured out and were just curious if there might be another way to do it.

What I am thinking is that the name up in your URL is probably going to be the same as this variable on your page: $church_endRecord['title']

So we could just do something like,

if name from url = the name we are showing in the navigation, change its style

Does that sound like it would work? Let me know what you think :).
-----------------------------------------------------------
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: [ross] If statement to style navigation/current page

By Kittybiccy - May 21, 2009

Hi Ross,

The url's for the pages end in:
/napton.php?1, napton.php?2 etc (so numbered depending where the put the pages in the CMSB list)

Until you get to the teamList/teamDetail page where it is: napton_teamList.php/napton_teamDetail.php?Head-Teacher-5.

Would this have any effect?