Advertisement:

Author Topic: Quick Question Regarding Horizontal Navigation  (Read 7367 times)

jack daniels

  • Newbie
  • *
  • Posts: 15
Quick Question Regarding Horizontal Navigation
« on: March 31, 2010, 10:42:11 pm »
I have built a simple CSS dropdown horizontal navigation, user scrolls over categories and the dropdown shows the respective sub-cats, (nice for webmasters with a smaller number of sub-cats)

Works great on the homepage, but with it being horizontal im needing it to be either hardcoded into the header or pulled into the header as a serverside include from a separate file nav.php for example so it is included on every page..

Hardcoding into the header or using a serverside include both throw out these errors

Code: [Select]
Notice: Undefined variable: categories in C:\wamp\www\oscom\oc-content\themes\simply\header.php  on line 124

Warning: Invalid argument supplied for foreach() in C:\wamp\www\oscom\oc-content\themes\simply\header.php on line 124

this even happens if i cut and copy the dropdown code from home.php and put it at the very end of the header.php code, any ideas?
thanks

Max P

  • Newbie
  • *
  • Posts: 19
Re: Quick Question Regarding Horizontal Navigation
« Reply #1 on: April 01, 2010, 01:15:08 pm »
It seems that variable categories is missing.

My first guess is that $categories var is accessible only after header is generated. Fast hack will be to make following action to oc-includes/osclass/themes.php:

Replace this function:
Code: [Select]
function osc_renderHeader($headerConf = array()) {
global $preferences;
$themePath = THEMES_PATH . $preferences['theme'] . '/header.php';
if(file_exists($themePath))
require $themePath;
}

WITH

Code: [Select]
function osc_renderHeader($headerConf = array()) {
global $preferences;
global $categories;
$themePath = THEMES_PATH . $preferences['theme'] . '/header.php';
if(file_exists($themePath))
require $themePath;
}

this should make a trick.

jack daniels

  • Newbie
  • *
  • Posts: 15
Re: Quick Question Regarding Horizontal Navigation
« Reply #2 on: April 01, 2010, 07:04:48 pm »
Thanks for taking the time Max P, that works a treat... almost

The good thing is i can now use a serverside include and i can also add the code to the bottom of the header and it works, the downside is it only works when on the themes home page when i navigate away (item.php) for example it then returns the

Code: [Select]
Warning: Invalid argument supplied for foreach() in C:\wamp\www\oscom\oc-content\themes\simply\header.php on line 124
which refers to this line

<?php foreach($categories as $c): ?>

Max P

  • Newbie
  • *
  • Posts: 19
Re: Quick Question Regarding Horizontal Navigation
« Reply #3 on: April 01, 2010, 07:14:09 pm »
This is because item.php has $categories = Category::newInstance()->toTree(); inside post action. Try to move it to the top after line 17: osc_dbAutoConnect(); :)

Hope this helps.

I think we will have to do some changes to the code to make it work. I bet you are not the only one who wants to have categories available in header!

jack daniels

  • Newbie
  • *
  • Posts: 15
Re: Quick Question Regarding Horizontal Navigation
« Reply #4 on: April 01, 2010, 07:23:08 pm »
My mistake Max P, item.php works fine now without any changes, it is category.php where the error shows

Horizontal would be a nice option for a site with fewer sub-cats, possibly further down the development line have a checkbox in ACP for either Horizontal or Vertical (vertical is better for more sub-cats with-out them flying of screen)

Max P

  • Newbie
  • *
  • Posts: 19
Re: Quick Question Regarding Horizontal Navigation
« Reply #5 on: April 01, 2010, 07:41:18 pm »
You can try to add $categories = Category::newInstance()->toTree(); to category.php and it should work fine after that.

jack daniels

  • Newbie
  • *
  • Posts: 15
Re: Quick Question Regarding Horizontal Navigation
« Reply #6 on: April 01, 2010, 08:02:01 pm »
Success! Thankyou very much for your input

 Would not work from category.php, however i dropped the line of code into my modified header.php above <?php foreach($categories as $c): ?> and all is good and working as it should do,

 I will upload a demo of it to my server for you to look at later next week (Easter holidays and things coming up) in the meantime i will check for cross-browser compliancy and SEO a few things in the themes code.

 A point i would like to make is because this theme use's a horizontal menu the homepage is bare of content, but im sure this will improve as the project develops..

jack daniels

  • Newbie
  • *
  • Posts: 15
Re: Quick Question Regarding Horizontal Navigation
« Reply #7 on: April 01, 2010, 08:18:51 pm »
Just in case anybody else is interested i also had to add this line into ../user.php as the registration page would not show the menu
"require_once 'osclass/model/Category.php';"