CSS Dropdown Menu

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
Paal
Posts: 204
Joined: Wed 6. Oct 2004, 19:54
Location: Budapest, Hungary
Contact:

Re: Have you seen this?

Post by Paal »

Lumimies wrote:http://ionrock.umemusic.com/index.php?id=5,8,0,0,1,0

Look at the bottom of the page

"Structure Nav Using Lists (no tables)"

by Ionrock
Hello!

I have a little problem. I use this hack and comes this source:

Code: Select all

<ul>
<li><a href="index.php?id=1,0,0,1,0,0">News</a></li>
<li><a href="index.php?id=3,0,0,1,0,0">Contact</a></li>
<li><a href="index.php?id=2,0,0,1,0,0">Downloads</a></li>
<li><a class="cell_active" href="index.php?id=6,0,0,1,0,0">Links</a></li>
<ul>
</ul>
<li><a href="index.php?id=4,0,0,1,0,0">Sitemap</a></li>
<li><a href="index.php?id=5,0,0,1,0,0">Guestbook</a></li>
</ul>
why not this?

Code: Select all

<ul>
<li><a href="index.php?id=1,0,0,1,0,0">News</a></li>
<li><a href="index.php?id=3,0,0,1,0,0">Contact</a></li>
<li><a href="index.php?id=2,0,0,1,0,0">Downloads</a></li>
<li><a class="cell_active" href="index.php?id=6,0,0,1,0,0">Links</a></li>
<li><a href="index.php?id=4,0,0,1,0,0">Sitemap</a></li>
<li><a href="index.php?id=5,0,0,1,0,0">Guestbook</a></li>
</ul>
This is the mod/hack:

Code: Select all

/* 
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
THIS HAS BEEN EDITED TO CREATE A LIST MENU !!!!!!!!!
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
*/
function nav_list_struct ($struct, $act_cat_id, $level, $nav_table_struct, $link_to="index.php") {
	// start with home directory for the listing = top nav structure
	// 1. Build the recursive tree for given actual article category ID
	
	// return the tree starting with given start_id (like breadcrumb)
	// if the $start_id = 0 then this stops because 0 = top level
	
	$level = intval($level);
	$start_id = $act_cat_id;
	
	while ($start_id) {
		$data[$start_id] = 1;
		$start_id		 = $struct[$start_id]["acat_struct"];
	}
	$temp_tree = (sizeof($data)) ? array_reverse($data, 1) : false;
	
	foreach($struct as $key => $value) {
		if($struct[$key]["acat_struct"] == $act_cat_id && $key && !$struct[$key]["acat_hidden"]) $c++;
	}
	$c = (!$c) ? 1 : 0;
	
	//get depth of level
	$level_depth = 0; $start_level = $level;
	while ($start_level) {
		$start_level = $struct[$start_level]["acat_struct"];
		$level_depth++;
	}
	$temp_menu = build_list ($struct, $level, $temp_tree, $act_cat_id, $nav_table_struct, $level_depth, $c, $link_to); //starts at root level
	return ($temp_menu) ? ($temp_menu) : "";
}

// -------------------------------------------------------------

function build_list ($struct, $level, $temp_tree, $act_cat_id, $nav_table_struct, $count, $div, $link_to) {
	// this returns the level structure based on given arrays
	// it is special for browsing from root levels
	$depth = sizeof($temp_tree)-$div; $count++; 
	$depth2 = $depth-$count+2;
	$colspan	= ($depth2 > 1) ? " colspan="".$depth2.""" : "";
	$temp_menu .= "<ul>\n";
	foreach($struct as $key => $value) {
		if($_SESSION["frontend_user_in"] && $struct[$key]["acat_regonly"]) 
			$struct[$key]["acat_regonly"] = 0;
			
		if($struct[$key]["acat_struct"] == $level && $key && !$struct[$key]["acat_hidden"] && !$struct[$key]["acat_regonly"]) {
			
			$link			= $link_to."?id=".$key.",0,0,1,0,0";
			
			if($temp_tree[$key]) {
				if($act_cat_id == $key) {
					$temp_menu .= "<li><a class="cell_active" href="".$link."">".html_specialchars($struct[$key]["acat_name"])."</a></li>\n";
				} else {
					$temp_menu .= "<li><a href="".$link."">".html_specialchars($struct[$key]["acat_name"])."</a></li>\n";
				}
				
				$temp_menu .= build_list ($struct, $key, $temp_tree, $act_cat_id, $nav_table_struct, $count, $div, $link_to);
			} else {
				$temp_menu .= "<li><a href="".$link."">".html_specialchars($struct[$key]["acat_name"])."</a></li>\n";
			}
		}
	}
	$temp_menu .= "</ul>\n";
	if($nav_table_struct["row_space"] && $count == 1) $temp_menu .= $space_row;

	
	return $temp_menu;
}


/* 
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
THIS HAS BEEN EDITED TO CREATE A LIST MENU !!!!!!!!!
[][][][][][][][][][][][][][][][][][][][][][][][][][][][][]
*/
Tnx, Paul
ionrock
Posts: 279
Joined: Fri 20. Feb 2004, 17:04

Post by ionrock »

It does that b/c I took it from the main menu replacement tag (I think ;)). I have been using the more recent {NAV_LIST} and {NAV_CURRENT} . Take a look at how those work and you should be able to come up with a better solution. That hack was from a long time ago and a lot has changed since then.
Paal
Posts: 204
Joined: Wed 6. Oct 2004, 19:54
Location: Budapest, Hungary
Contact:

Post by Paal »

ionrock wrote:It does that b/c I took it from the main menu replacement tag (I think ;)). I have been using the more recent {NAV_LIST} and {NAV_CURRENT} . Take a look at how those work and you should be able to come up with a better solution. That hack was from a long time ago and a lot has changed since then.
My coder friend check source and correct it (I hope :) ):

Code: Select all

function build_list ($struct, $level, $temp_tree, $act_cat_id, $nav_table_struct, $count, $div, $link_to) {
	// this returns the level structure based on given arrays
	// it is special for browsing from root levels
	$depth = sizeof($temp_tree)-$div; $count++; 
	$depth2 = $depth-$count+2;
	$colspan	= ($depth2 > 1) ? " colspan="".$depth2.""" : "";
	$temp_menu .= "<ul>\n";
	foreach($struct as $key => $value) {
		if($_SESSION["frontend_user_in"] && $struct[$key]["acat_regonly"]) 
			$struct[$key]["acat_regonly"] = 0;
			
		if($struct[$key]["acat_struct"] == $level && $key && !$struct[$key]["acat_hidden"] && !$struct[$key]["acat_regonly"]) {
			
			$link			= $link_to."?id=".$key.",0,0,1,0,0";
			
			if($temp_tree[$key]) {
				if($act_cat_id == $key) {
					$temp_menu .= "<li><a class="cell_active" href="".$link."">&raquo;&nbsp;".html_specialchars($struct[$key]["acat_name"])."</a></li>\n";
				} else {
					$temp_menu .= "<li><a href="".$link."">&raquo;&nbsp;".html_specialchars($struct[$key]["acat_name"])."</a></li>\n";
				}
				
				$temp_menu .= build_list ($struct, $key, $temp_tree, $act_cat_id, $nav_table_struct, $count, $div, $link_to);
			} else {
				$temp_menu .= "<li><a href="".$link."">&raquo;&nbsp;".html_specialchars($struct[$key]["acat_name"])."</a></li>\n";
			}
		}
	}

// Thifi start
	if(trim($temp_menu) == "<ul>")
		return "";
// Thifi end

	$temp_menu .= "</ul>\n";
	if($nav_table_struct["row_space"] && $count == 1) $temp_menu .= $space_row;
	
	return $temp_menu;
}
The source is correct now:

Code: Select all

<ul>
<li><a href="index.php?id=106,0,0,1,0,0">Menu1</a></li>
<li><a class="cell_active" href="index.php?id=95,0,0,1,0,0">Menu1</a></li>
<li><a href="index.php?id=96,0,0,1,0,0">Menu1</a></li>
<li><a href="index.php?id=97,0,0,1,0,0">Menu2</a></li>
<li><a href="index.php?id=98,0,0,1,0,0">Menu3</a></li>
<li><a href="index.php?id=99,0,0,1,0,0">Menu4</a></li>
</ul>
and

Code: Select all

<ul>
<li><a href="index.php?id=34,0,0,1,0,0">Menu1</a></li>
<li><a href="index.php?id=52,0,0,1,0,0">Menu2</a></li>
<li><a href="index.php?id=56,0,0,1,0,0">Menu3</a></li>
<li><a href="index.php?id=58,0,0,1,0,0">Menu4</a></li>
<li><a href="index.php?id=61,0,0,1,0,0">Menu5</a></li>
<li><a class="cell_active" href="index.php?id=62,0,0,1,0,0">Menu6</a></li>
	<ul>
		<li><a href="index.php?id=63,0,0,1,0,0">subMenu1</a></li>
		<li><a href="index.php?id=64,0,0,1,0,0">subMenu2</a></li>
	</ul>
</ul>
Your mind?

Paul
frold
Posts: 2151
Joined: Tue 25. Nov 2003, 22:42

Post by frold »

a demo paul?
http://www.studmed.dk Portal for doctors and medical students in Denmark
Paal
Posts: 204
Joined: Wed 6. Oct 2004, 19:54
Location: Budapest, Hungary
Contact:

Post by Paal »

frold wrote:a demo paul?
Sorry, only localhost now. 1-2 weeks for public.

P.
frold
Posts: 2151
Joined: Tue 25. Nov 2003, 22:42

Post by frold »

Paal wrote:
frold wrote:a demo paul?
Sorry, only localhost now. 1-2 weeks for public.

P.
you can set up a dns ;D

http://www.no-ip.com :D
http://www.studmed.dk Portal for doctors and medical students in Denmark
Paal
Posts: 204
Joined: Wed 6. Oct 2004, 19:54
Location: Budapest, Hungary
Contact:

Post by Paal »

frold wrote:
Paal wrote:
frold wrote:a demo paul?
Sorry, only localhost now. 1-2 weeks for public.

P.
you can set up a dns ;D

http://www.no-ip.com :D
I have one public demo site. Tomorrow I publish this mod+hack, ok?

Paul
frold
Posts: 2151
Joined: Tue 25. Nov 2003, 22:42

Post by frold »

Paal you are a guru!! 8)
http://www.studmed.dk Portal for doctors and medical students in Denmark
Paal
Posts: 204
Joined: Wed 6. Oct 2004, 19:54
Location: Budapest, Hungary
Contact:

Post by Paal »

frold wrote:Paal you are a guru!! 8)
I'am not a guru :(

Check the link: http://www.carp.hu/terkep2/index.php?id=11,0,0,1,0,0

from:

Code: Select all

function build_list ($struct, $level, $temp_tree, $act_cat_id, $nav_table_struct, $count, $div, $link_to) {
        // this returns the level structure based on given arrays
        // it is special for browsing from root levels
        $depth = sizeof($temp_tree)-$div; $count++;
        $depth2 = $depth-$count+2;
        $colspan        = ($depth2 > 1) ? " colspan="".$depth2.""" : "";
        $temp_menu .= "<ul>\n";
        foreach($struct as $key => $value) {
                if($_SESSION["frontend_user_in"] && $struct[$key]["acat_regonly"])
                        $struct[$key]["acat_regonly"] = 0;

                if($struct[$key]["acat_struct"] == $level && $key && !$struct[$key]["acat_hidden"] && !$struct[$key]["acat_regonly"]) {

                        $link                   = $link_to."?id=".$key.",0,0,1,0,0";

                        if($temp_tree[$key]) {
                                if($act_cat_id == $key) {
                                        $temp_menu .= "<li><a class="cell_active" href="".$link."">".html_specialchars($struct[$key]["acat_name"])."</a></li>\n";
                                } else {
                                        $temp_menu .= "<li><a href="".$link."">".html_specialchars($struct[$key]["acat_name"])."</a></li>\n";
                                }

                                $temp_menu .= build_list ($struct, $key, $temp_tree, $act_cat_id, $nav_table_struct, $count, $div, $link_to);
                        } else {
                                $temp_menu .= "<li><a href="".$link."">".html_specialchars($struct[$key]["acat_name"])."</a></li>\n";
                        }
                }
        }

        $temp_menu .= "</ul>\n";
        if($nav_table_struct["row_space"] && $count == 1) $temp_menu .= $space_row;

        return $temp_menu;
}
to:

Code: Select all

function build_list ($struct, $level, $temp_tree, $act_cat_id, $nav_table_struct, $count, $div, $link_to) {
        // this returns the level structure based on given arrays
        // it is special for browsing from root levels
        $depth = sizeof($temp_tree)-$div; $count++;
        $depth2 = $depth-$count+2;
        $colspan        = ($depth2 > 1) ? " colspan="".$depth2.""" : "";
        $temp_menu .= "<ul>\n";
        foreach($struct as $key => $value) {
                if($_SESSION["frontend_user_in"] && $struct[$key]["acat_regonly"])
                        $struct[$key]["acat_regonly"] = 0;

                if($struct[$key]["acat_struct"] == $level && $key && !$struct[$key]["acat_hidden"] && !$struct[$key]["acat_regonly"]) {

                        $link                   = $link_to."?id=".$key.",0,0,1,0,0";

                        if($temp_tree[$key]) {
                                if($act_cat_id == $key) {
                                        $temp_menu .= "<li><a class="cell_active" href="".$link."">".html_specialchars($struct[$key]["acat_name"])."</a></li>\n";
                                } else {
                                        $temp_menu .= "<li><a href="".$link."">".html_specialchars($struct[$key]["acat_name"])."</a></li>\n";
                                }

                                $temp_menu .= build_list ($struct, $key, $temp_tree, $act_cat_id, $nav_table_struct, $count, $div, $link_to);
                        } else {
                                $temp_menu .= "<li><a href="".$link."">".html_specialchars($struct[$key]["acat_name"])."</a></li>\n";
                        }
                }
        }

// Thifi start
        if(trim($temp_menu) == "<ul>")
                return "";
// Thifi end

        $temp_menu .= "</ul>\n";
        if($nav_table_struct["row_space"] && $count == 1) $temp_menu .= $space_row;

        return $temp_menu;
}

Results:

Code: Select all

<ul>
  <li><a href="index.php?id=11,0,0,1,0,0">Menu 1</a></li>
    <ul>
      <li><a class="cell_active" href="index.php?id=12,0,0,1,0,0">SubMenu 1/1</a></li>
        <ul>
          <li><a href="index.php?id=20,0,0,1,0,0">SubSub 1/1/1</a></li>
        </ul>
      <li><a href="index.php?id=14,0,0,1,0,0">SubMenu 1/2</a></li>
    </ul>
  <li><a href="index.php?id=13,0,0,1,0,0">Menu 2</a></li>
  <li><a href="index.php?id=16,0,0,1,0,0">Menu 4</a></li>
  <li><a href="index.php?id=15,0,0,1,0,0">Menu 3</a></li>
</ul>
Ionrock!

Please check the source and public your site (my site temporary).

Tnx, Paul
frold
Posts: 2151
Joined: Tue 25. Nov 2003, 22:42

Post by frold »

nice - great job ;-)
http://www.studmed.dk Portal for doctors and medical students in Denmark
ionrock
Posts: 279
Joined: Fri 20. Feb 2004, 17:04

Post by ionrock »

As I said, sorry for old code. I don't publicize that site anymore and I can't do much about old forum posts. :(
Paal
Posts: 204
Joined: Wed 6. Oct 2004, 19:54
Location: Budapest, Hungary
Contact:

Post by Paal »

ionrock wrote:As I said, sorry for old code. I don't publicize that site anymore and I can't do much about old forum posts. :(
Okey, but do you allow to publish it on "phpwcms-docu.de" site?

Tnx, Paul
frold
Posts: 2151
Joined: Tue 25. Nov 2003, 22:42

Post by frold »

Paal wrote:
ionrock wrote:As I said, sorry for old code. I don't publicize that site anymore and I can't do much about old forum posts. :(
Okey, but do you allow to publish it on "phpwcms-docu.de" site?

Tnx, Paul
the fixed version I guess ;-)
http://www.studmed.dk Portal for doctors and medical students in Denmark
frold
Posts: 2151
Joined: Tue 25. Nov 2003, 22:42

Post by frold »

howto get the whole list listed like

<ul>
<li><a href="">Menu1</a></li>
<ul>
<li><a href="">subMenu1.1</a></li>
<li><a href="">subMenu1.2</a></li>
</ul>
<li><a href="">Menu2</a></li>
<ul>
<li><a href="">subMenu2.1</a></li>
<li><a href="">subMenu2.2</a></li>
</ul>
<li><a href="">Menu3</a></li>
<ul>
<li><a href="">subMenu3.1</a></li>
<li><a href="">subMenu3.2</a></li>
</ul>
<li><a href="">Menu4</a></li>
<li><a href="">Menu5</a></li>
<li><a href="">Menu6</a></li>
<ul>
<li><a href="">subMenu6.1</a></li>
<li><a href="">subMenu6.2</a></li>
</ul>
</ul>

At the moment you have to press on a level to "open" it.. I would like a output that gives you the whole list....
http://www.studmed.dk Portal for doctors and medical students in Denmark
brans

Post by brans »

You can see a working example that is nearly built into phpwcms of a css dropdown menu here
Post Reply