SitePoint Sponsor |
|
User Tag List
Results 1 to 19 of 19
-
May 7, 2009, 09:46 #1
- Join Date
- Apr 2008
- Location
- Sweden
- Posts
- 75
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Need help with printing array menu tree in a special way
I have a tree menu based on arrays that I need help with. I've uploaded my menu test version at the following address: http://websitefactory.se/menu.php so you can see how it looks.
The code to the test page for the menu: http://pastebin.com/mafcee87
Now on to my problem!
My problem:
Right now the menu would appear under the following principle:
Code:Page 1 Page 2 - Page 2.1 - Page 2.2 - Page 2.2.1 - Page 2.2.2 - Page 2.3 Page 3 Page 4
Code:- Page 2.2.1 - Page 2.2.2 - Page 2 - Page 2.1 - Page 2.3 Page 1 Page 3 Page 4
It would mean much for me to make it work. So please take a look and try help me!Thank you!
Last edited by Peter Westerlund; May 7, 2009 at 10:32.
-
May 8, 2009, 00:33 #2
- Join Date
- Apr 2008
- Location
- Sweden
- Posts
- 75
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Anyone? Please
-
May 8, 2009, 03:24 #3
-
May 8, 2009, 05:48 #4
- Join Date
- Apr 2008
- Location
- Sweden
- Posts
- 75
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It may seem illogical, but I still think it is quite logical. What it does is that it shows the most relevant menu links to the page as high up on the page as possible, the first your eyes read. 2 should be located as a link title above the 2.1 and 2.3, at the same level. I don't think it's illogical. However, the question is if it's possible to do?
-
May 8, 2009, 06:06 #5
- Join Date
- Sep 2006
- Location
- Nottingham, UK
- Posts
- 3,133
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Why is 2 at the same level as its children, but no others are like this? You need to clearly define the 'rules' for how it is laid out first (unambiguously), because I still don't really understand your thinking. It will almost certainly be possible, you need to define what you want a bit better though. Saying 'put the most relevant links as high up as possible' is very vague - how do you determine what is relevant? How high up should they go?
-
May 8, 2009, 07:03 #6
- Join Date
- Apr 2008
- Location
- Sweden
- Posts
- 75
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Since the top level has no parent, no parent can be a link-header above those top links. The next level has a parent from the top level. And it's not the level that the page we are visiting is on, therefore, the level's parent shall be printed above their children. When printed above their children, it should not be printed at the level it actually belongs to.
-
May 8, 2009, 07:44 #7
-
May 8, 2009, 09:40 #8
- Join Date
- Apr 2008
- Location
- Sweden
- Posts
- 75
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Code:- Page 2.2 - Page 2.2.1 - Page 2.2.2 - Page 2 - Page 2.1 - Page 2.3 Page 1 Page 3 Page 4
-
May 8, 2009, 10:02 #9
- Join Date
- Jul 2006
- Location
- Augusta, Georgia, United States
- Posts
- 4,194
- Mentioned
- 17 Post(s)
- Tagged
- 5 Thread(s)
What would the HTML look like?
-
May 8, 2009, 10:05 #10
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
I kind of understand what you're trying to do, but I really don't see any benefit of doing it at all. In fact, it will be pretty nasty to navigate. Usability-wise, it isn't a good idea.
Surely simply highlighting the current page or something would make more sense?Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
May 8, 2009, 10:21 #11
- Join Date
- Apr 2008
- Location
- Sweden
- Posts
- 75
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
For the context that the menu will be used in it will be very logical and practical. I will also use up arrows and mark clearly who are parents. I don't want it to be a discussion if the structure is logical or not. I just want to know how to make this possible.
-
May 8, 2009, 10:36 #12
- Join Date
- May 2006
- Location
- Lancaster University, UK
- Posts
- 7,062
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
My point is that if people who work with structure and logic every day think it sounds needlessly complicated, ordinary users will think so even more.
Anyway, others have asked questions and unless you answer them, none of us can help you.Jake Arkinstall
"Sometimes you don't need to reinvent the wheel;
Sometimes its enough to make that wheel more rounded"-Molona
-
May 8, 2009, 10:43 #13
- Join Date
- Apr 2008
- Location
- North Carolina
- Posts
- 438
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Here's a starting point for ya.
PHP Code:<?php
$myarr = array(
'1' => array(
'1.1' => array(
'1.1.1'
,'1.1.2'
)
,'1.2' => array(
'1.2.1'
,'1.2.2'
)
)
,'2' => array(
'2.1' => array(
'2.1.1'
)
)
,'3' => array(
'3.1' => array(
'3.1.1'
)
)
);
$curpage = '2';
$curpage_arr = $myarr[$curpage];
unset($myarr[$curpage]);
echo "<pre>";
print_r($curpage_arr);
print_r(array_reverse($myarr, TRUE));
echo "</pre>";[read: PHP Sec. | CSRF | PCRE Mods | Encryption | Form Proc. | File Val.]
[tools: PHPEd | PHP Docs | jQuery | CI | SwiftMailer | CKEditor | reCAPTCHA]
-
May 11, 2009, 07:15 #14
- Join Date
- Apr 2008
- Location
- Sweden
- Posts
- 75
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Now I've tried a lot of possible variations. I feel that I soon reached the target. Now the code for the function to build the menu looks like this:
PHP Code:<? function tree_menu($array,$sel)
{
$find = $sel;
foreach ($array as $code => $info)
{
if (findKeyRecursive($find, $info))
$sele = $code;
}
foreach ($array as $key => $value)
{
if (is_array($value['submenu']))
{
$level[$key] = array('name' => $value['name'], 'href' => $value['href'], 'submenu' => $value['submenu']);
if ($sele == $key or $sel == $key)
{
tree_menu($value['submenu'],$sel);
}
}
else
{
$level[$key] = array('name' => $value['name'], 'href' => $value['href']);
}
}
echo '<ul>';
foreach ($level as $key => $value)
{
if ($sel !== $key)
{
echo '<li><a href="'.$value['href'].'">'.$value['name'].'</a></li>';
}
}
echo '</ul>';
} ?>
http://websitefactory.se/menu.php?sel=page221
The only problem left is to get the parent to appear above their children rather than to lie in its corresponding level. Anybody know how to do it?
-
May 11, 2009, 08:23 #15
-
May 11, 2009, 08:27 #16
- Join Date
- Apr 2008
- Location
- Sweden
- Posts
- 75
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
No, I acually want them to be separated. I will show the result when I got it to work
-
May 11, 2009, 09:08 #17
-
May 11, 2009, 09:11 #18
- Join Date
- Apr 2008
- Location
- Sweden
- Posts
- 75
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Sure, that will work as well. But I still want the parents to be above their childs.
-
May 12, 2009, 11:11 #19
- Join Date
- Apr 2008
- Location
- Sweden
- Posts
- 75
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Anyone? please
Bookmarks