Navigation

12 posts by 2 authors in: Forums > CMS Builder
Last Post: September 5, 2009   (RSS)

Hi,

I have a problem with the navigation working correctly. I have four main navigation items and two of them have secondary navigation. The navigation is a drop down hover build using CSS. I have created the code so that the CMS can name both the main and secondary navigation items rather than having to hard code the main navigation. This navigation is also included in the page using an include.

when i select the on of the main navigation items that has a secondary navigation under it, the page loads correctly, but the seondary navigation then doesn't display on the hover and it is meant to.

Also, when i select one of the secondary navigation, the page again loads correctly except that the main navigation that it is situated under disappears off the site until you click onto another page.

Below is the code that I wrote for the navigation (which worked on another site I was developing).

<div class="line"></div>
<img class="logo" src="images/logo.jpg" alt="Janizm" />
<div id="topNav">
<ul>
<li><a href="index.php">
<?php foreach ($indexRecords as $record): ?>
<?php echo $record['navigation_name'] ?>
<?php endforeach; ?>
</a></li>
<li>
<?php foreach ($galleryRecords as $record): ?>
<?php if ($record['depth'] == 0): ?>
<a href="<?php echo $record['_link'] ?>"><?php echo $record['navigation_name'] ?></a>
<?php elseif ($record['depth'] == 1): ?>
<ul>
<li><a href="<?php echo $record['_link'] ?>"><?php echo $record['navigation_name'] ?></a></li>
</ul>
<?php endif ?>
<?php endforeach; ?>
</li>
<li>
<?php foreach ($linksRecords as $record): ?>
<?php if ($record['depth'] == 0): ?>
<a href="<?php echo $record['_link'] ?>"><?php echo $record['navigation_name'] ?></a>
<?php elseif ($record['depth'] == 1): ?>
<ul>
<li><a href="<?php echo $linksRecords['_link'] ?>"><?php echo $record['navigation_name'] ?></a></li>
</ul>
<?php endif ?>
<?php endforeach; ?>
</li>
<li><a href="contact.php">
<?php foreach ($contactRecords as $record): ?>
<?php echo $record['navigation_name'] ?>
<?php endforeach; ?>
</a></li>
</ul>
</div>

Suggestions would be very much appriciated.

Re: [dsternalski] Navigation

By Chris - August 27, 2009

Hi dsternalski,


The navigation is a drop down hover build using CSS.


If things are disappearing on you, I'm guessing the problem has to do with a combination of how the page is structured and how your dynamic drop-down hover code works. Do you have a URL I can check out to see the problem in action?
All the best,
Chris

Re: [dsternalski] Navigation

By Chris - August 29, 2009

Hi dsternalski,

Wow, that's some complicated code you've got going on there.

I think I figured out what you mean by "the page now displays both pages on one".

Here's the part of your Gallery Detail page where you get records from the server:

list($galleryRecords, $galleryMetaData) = getRecords(array(
'tableName' => 'gallery',
//'where' => whereRecordNumberInUrl(1),
//'limit' => '1',
));
$galleryRecord = @$galleryRecords[0]; // get first record


I notice that you've commented out the code which selects a single record based on the query string. I'm assuming you're doing this so that you can use the same Record Set to list all the galleries in your Navigation Include. Unfortunately, this approach leaves your single record variable ($galleryRecord) set to the first record in the section every time (and not to the record the user wants to view.)

Furthermore, the code on your Gallery Detail page uses foreach statements to loop over all the records in $galleryRecords (which is all the records in that section,) displaying each of them instead of a single record:

<title><?php foreach ($galleryRecords as $record): ?><?php echo $record['name'] ?><?php endforeach ?></title>
...
<?php foreach ($galleryRecords as $record): ?>
...
<?php echo $record['content'] ?>
...
'FlashVars','xmlfile=http://localhost/janizm/images.xml.php?recordNum=<?php echo $record ['num']?>'
...
<?php endforeach ?>


Let's simplify things.

First off, let's isolate your Navigation Include so that it uses its own variables instead of sharing variables with the rest of your pages. We can do this by choosing unique variable names. Below, I've chosen the names $allIndexRecords, $allGalleryRecords, $allLinksRecords, and $allContactRecords.

<?php

list($allIndexRecords, $indexMetaData) = getRecords(array(
'tableName' => 'index'
));
list($allGalleryRecords, $galleryMetaData) = getRecords(array(
'tableName' => 'gallery'
));
list($allLinksRecords, $linksMetaData) = getRecords(array(
'tableName' => 'links',
));
list($allContactRecords, $contactMetaData) = getRecords(array(
'tableName' => 'contact',
));
?>
<ul>
...


I think we can omit your $navigation variable, right? That looks like it was just there for testing.

Let's leave those navigation lists flat for now and we can come back to making them properly indented after everything else is working:

...
<ul>
<?php foreach ($allIndexRecords as $record): ?>
<li><a href="<?php echo $record['_link'] ?>"><?php echo $record['navigation_name'] ?></a></li>
<?php endforeach; ?>
<?php foreach ($allGalleryRecords as $record): ?>
<li><a href="<?php echo $record['_link'] ?>"><?php echo $record['navigation_name'] ?></a></li>
<?php endforeach; ?>
<?php foreach ($allLinksRecords as $record): ?>
<li><a href="<?php echo $record['_link'] ?>"><?php echo $record['navigation_name'] ?></a></li>
<?php endforeach; ?>
<?php foreach ($allContactRecords as $record): ?>
<li><a href="<?php echo $record['_link'] ?>"><?php echo $record['navigation_name'] ?></a></li>
<?php endforeach; ?>
</ul>


Now that your Navigation Include works, let's readdress your Gallery Detail page, which only needs a single getRecords() call and should not have a single foreach statement in it:

list($galleryRecords, $galleryMetaData) = getRecords(array(
'tableName' => 'gallery',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$record = @$galleryRecords[0]; // get first record
...
<title><?php echo $record['name'] ?></title>
...
<?php include("navigation/navigation.php"); ?>
...
<?php echo $record['content'] ?>
...
'FlashVars','xmlfile=http://localhost/janizm/images.xml.php?recordNum=<?php echo $record['num'] ?>'
...


I hope this helps you! Please let us know when you've got that working or if you run into any trouble.

P.S. It might be easier for people to help you if you use forum tags around your code, or upload your code as attachment(s). Reading unindented code can be difficult.
All the best,
Chris

Re: [chris] Navigation

hi, thanks again for your reply. i tried the code that you sent, and it still doesn't seem to fix the problem.

Re: [dsternalski] Navigation

By Chris - September 1, 2009

Hi dsternalski,

Can you post your current code (as forum attachments please, they're much easier to read with indentation) and maybe provide a link to an example page where I can see what the problem is?
All the best,
Chris

Re: [chris] Navigation

By dsternalski - September 2, 2009 - edited: September 2, 2009

hi,

Please find the code for both the navigation and the Gallery page(s) attached.

I am in the process of sorting out somewhere to upload the test site too, so i should have a link soon, so i have attached a screen shot to explain.

As you know the navigation is built in CSS and is flyout rollover navigation. Gallery is meant to situate under gallery 22 (the same with both the links buttons in the navigation).

However, when you click on the gallery link, it displays the correct url as does gallery 22, but the content on the page no matter the url is the same.

Re: [dsternalski] Navigation

By Chris - September 3, 2009

A ha! I think I know what the problem is.

Your gallery.php page loads a "gallery" record into a variable called $record, then it includes your navigation.php page which uses the same variable ($record) in its foreach loops. That will overwrite your variable, so that when you go to output $record['content'] later in the page, you're no longer using the same record.

Try this: change every occurrence of $record in your gallery.php page to $selectedGalleryRecord; leave the $record variables in navigation.php as $record.

Please let me know if this doesn't fix your problem and I'll have another look. :)
All the best,
Chris

Re: [chris] Navigation

hi thank you! that worked!

how do i now get the navigation to work the way that i want it to with the secondary navigation as a selection on the main navigation like on http://www.web--templates.org/menus/css-flyout-menu.html (the actual navigation function)?

thank you again!

Re: [dsternalski] Navigation

By Chris - September 4, 2009

Hi dsternalski,

I'm afraid I've never used Deluxe Menu. Can you provide an example of how to use it with static content, and I can hopefully show you how to get CMSb to populate it with your data?
All the best,
Chris