SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Addict Iceman90's Avatar
    Join Date
    Mar 2006
    Location
    Calgary, Alberta, Canada
    Posts
    391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Show current page and parents in multilevel navigation

    Hello all,

    I am currently building a site that is going to be 3 levels deep. What we want to do is to be able to highlight the current page that the user is on, as well as the parent and grandparent (section) of each link.

    There is no CMS or database behind this site, and as such no way to really have no way to know what pages are actually related to which other ones.

    To highlight the current page, I'd normally just do thos:
    Code PHP:
     <li><a <?php if (strpos($_SERVER['PHP_SELF'], 'index.php')) echo 'class="current"';?> href="index.php">Home Page</a></li>

    But I am trying to find the best way to find the parent and grandparent page. Am I best to just create 2 variables to target tthe higherarchy (sya $parent and $section), or would I be better to name all my pages as section1-sub1-page.php and use a function that checks the string of the filename for certain characters, and then creates the necessary variables? Or something else?

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Iceman90 View Post
    There is no CMS or database behind this site, and as such no way to really have no way to know what pages are actually related to which other ones.

    But I am trying to find the best way to find the parent and grandparent page.
    I think you've just answered your own problem. Or at least defined it. You have no way to know what pages are related to other ones. So you need to decide how you're doing to define that. The 'best' way is all the same way - a database table, or nested array/object, are (nearly) the same thing.

    Using excessively long pagenames is generally not the right solution, but it is one you can use. (what happens when you're 6 layers deep? index-food-desserts-chocolate-cake-doublechocolatefun.php ? what a mouthful.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by StarLion View Post
    index-food-desserts-chocolate-cake-doublechocolatefun.php ? what a mouthful.
    A mouthful of double chocolate fun? Hmmm!

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    If this feature has not been designed in from the beginning of the project, then you ought to be able to tack on meta-data derived from tables containing the relationships.

    main_categories
    ----------------
    id - category
    -------------
    1 | Desserts
    2 | Starters

    sub_categories
    ---------------
    id - main_ref - category
    ----------------------
    1 | 1 | Puddings
    2 | 1 | Cakes
    3 | 2 | Sea food

    items
    -----
    id - sub_ref - item
    -----------------
    1 | 1 | Sticky Toffee Pudding
    2 | 2 | Banana Cake
    3 | 3 | Prawn Cocktail

    You can do similar with single table using natural keys

    items
    ------
    main - sub - item
    ----------------
    Desserts - Puddings - Sticky Toffee Pudding
    Desserts - Puddings - Jam Rolly Polly

    Where you then make sure that all 3 fields enforce uniqueness, and then index the "item" for faster lookups - but you will be matching text to text - so will have to take that into consideration when say, renaming an item.

    You could just use and id number of course.

    All this will depend on how easily you introduce this to your cms backend - of course.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •