javascript - Navigation menu with php, js and mysql -
note: original & new inside code.
my issue here original "parent" not seo friendly , not act according plan, not fetched in sitemaps.
however new seo friendly, picked in sitemaps , according plan in end.
i need link can see both navigation menu left name of each menu / sub-menu , in center of page have picture name each sub-menu depending on parent click in navigation menu on left.
with new line added page refresh due link, sub-menus flash open second before refresh.
what need solving is:
-making sub-menu stay open during page refresh can use both navigation sidebar navigation , center navigation.
thanks in beforehand!
//jim
this current menu:
<div id="container"> <dl> <?php $select_category = mysql_query("select * menu hidden = 0 order menu asc"); while($ln = mysql_fetch_array($select_category)){ $idcat = $ln['nmr']; $catname = str_replace(' ', '-', $ln['menu']); ?> *original*: <dt><a href="#/<?php echo $catname; ?>/" style="color:#000;" ><strong><?php echo $ln['menu']; ?></strong></a></dt> *new*: <dt><a href="http://www.mysite.com/cats/<?php echo $msub['nmr'];?>/<?php echo $mname; ?>/" style="color:#000;" ><strong><?php echo $mn['menu']; ?></strong></a></dt> <?php $select_sub = mysql_query("select * submenu nmrmenu = '$idcat' , hidden = 0"); if(mysql_num_rows($select_sub) == 0){ }else { ?> <dd> <ul> <?php while($lsub = mysql_fetch_array($select_sub)){ $subname = str_replace(' ', '-', $lsub['submenu']); $pil = '»'; $brnr = $lsub['nmr']; ?> <li> <a href="http://www.mysite.com/cat/<?php echo $lsub['nmr'];?>/<?php echo $subname; ?>/" style="color:#333;"> <?php echo $pil; ?> <?php echo $lsub['submenu']; ?></a></li> <?php } ?> </ul> </dd> <?php } ?> </dl> <?php } ?> </div>
css:
#container{ margin:auto; margin-left:10px; } dl, dt, dd, ul, li, a{ margin:0; padding:0; } a{ text-decoration: none; color:#0f0; } li{ padding-left:.6em; list-style-type:none; color:#ff0; } dl{ width:100px; } dt{ }
js:
$(function() { $("dd:not(first)").hide(); $("dt a").click(function() { $("dd").slideup("normal"); $(this).parent("dt").next("dd").slidedown("normal"); }); });
here's jsfiddle of code.
first you'll want clean html , css. you're going want check page user viewing , if it's category, show specific sub navigation.
here's cleaned php/html. think you've messed variable names, if doesn't work, that's why.
example, have *new*: <dt><a href="http://www.mysite.com/cats/<?php echo $msub['nmr'];?>
$msub['nmr'];
not set in code above used.
<ul id="nav-container"> <?php $select_category = mysql_query("select * menu hidden = 0 order menu asc"); while ($ln = mysql_fetch_array($select_category)) { $idcat = $ln['nmr']; $catname = str_replace(' ', '-', $ln['menu']); echo '<li>' echo '<a href="http://www.mysite.com/cats/'.$msub['nmr'].'/'.$mname.'/" ><strong>'.$mn['menu'].'</strong></a>'; echo '<ul'; // check page you're on, , show sub navigation if corresponds page. if ($get['cat'] == $msub['nmr']) echo ' style="display:block;">'; else echo '>'; while ($lsub = mysql_fetch_array($select_sub)) { $subname = str_replace(' ', '-', $lsub['submenu']); $pil = '»'; $brnr = $lsub['nmr']; echo '<li><a href="http://www.mysite.com/cat/'.$lsub['nmr'].'/'.$subname.'/">'.$pil.' '.$lsub['submenu'].'</a></li>'; } echo '</ul>'; echo '</li>'; } ?> </ul>
here's css go it.
a { text-decoration: none; color: #333; } li { padding-left: .6em; list-style-type:none; color:#ff0; } #nav-container li ul { display: none; /* hide sub navigations start */ }
because of way used css, no longer need use javascript :)
Comments
Post a Comment