-4

my coding includes the following statement

<?php if ($openpage=="Navigation"){.subbar ul {height:102px; list-style-type:none; padding:0px;}?>

Parse error: syntax error, unexpected '.'

am still learning php, have I made a basic error that I am not seeing or is there another way to include the class statement. It is part of an expandable navbar that only expands the submenu on "hover". I am trying to get the submenu to stay expanded when on the parent page or one of the submenu pages

eg if on main page 1 - page 2 submenu = collapsed, if hovering over main page 2 - page 2 submenu = expanded, if on main page 2, main page 2 sub1 ... - page 2 submenu = collapsed - should be expanded.

Hope I've explained adequately what I am trying to do, have been unable to find any solutions on the web

u_mulder
  • 54,101
  • 5
  • 48
  • 64
user3601623
  • 5
  • 1
  • 3
  • You need to provide some code for diagnose – Panda Jan 31 '16 at 09:26
  • how can it be a duplicate my searches BEFORE posting the question the nearest error was for a ',' (comma) NOT '.' (full stop) c/ref my code copy (.subbar) above – user3601623 Jan 31 '16 at 16:53
  • have checked again '.' is part of a CLASS in css code IT IS NOT A CONCATENATION OR STRING so how can it be a duplicate? questions being rejected as duplicates out of context perhaps this is the wrong forum to ask such technical questions. I have supplied relevant sections of the coding yet still the rejection I REPEAT THE SYNTAX ERROR IS THE '.' OF '.class' NOT '.' ON ITS OWN. Simply rewording the question will therefore likely still cause an erroneous duplication rejection. As you require accurate error messages as well as question detail. – user3601623 Jan 31 '16 at 21:31

5 Answers5

0

When you output some data you should use echo or similar functions:

if ($openpage=="Navigation"){
    echo '.subbar ul {height:102px; list-style-type:none; padding:0px;}';
}
u_mulder
  • 54,101
  • 5
  • 48
  • 64
0
<?php if ($openpage=="Navigation"){.subbar ul {height:102px; list-style-type:none; padding:0px;}?>

Should be

<?php if ($openpage=="Navigation"){?>
    .subbar ul {
        height:102px; 
        list-style-type:none; 
        padding:0px;
    }
<?php } ?>
Matt
  • 2,851
  • 1
  • 13
  • 27
0

you can achieve that by knowing in which page the client is. so let's say the user is in page 1 we can have a php variable:

$current_page = 'page1';

and this variable changes depending on which page you are viewing.

then you can add css class to each submenu, for example submenu for page1 will have:

class="page1"

in the html attribute of the submenu.

after doing this you can simply use jquery to expand the submenu using the $current_page php variable as a css selector (for example):

$(document).ready(
    function() {
        $('ul.submenu.<?= $current_page ?>').addClass('expand');
    }
);

note: .addClass('expand') is just for explanation. you will have to use your own method and its usually done by adding a css class to the element

  • thanks for the advice but I don't really wnant to use javascript based coding - my appologies for not stating this in the original question. – user3601623 Jan 31 '16 at 16:41
0

As I see, you have confused CSS and PHP. Your code should be as Matt says, however, add the style tag:

<?php if ($openpage=="Navigation"){?>
   <style>
      .subbar ul {
         height:102px; 
         list-style-type:none; 
         padding:0px;
      }
   </style>
<?php } ?>
Nenomaz
  • 19
  • 3
0

luweiqi the php for this is

    <div class="navbar">
    <h4 <?php if ($openpage=="Navigation"){.subbar ul {height:102px;
    list-style-type:none; padding:0px;}?>>
    <a href="http://www.daypackrambler.co.uk/ramblertrialnavigation.php">
    Navigation<span class="navarrow">&#9660;</span></a></h4>
    <ul>
    <li <?php if ($openpage=="Compass") echo " id=\"currentpage\""; ?>>
    <a href="http://www.daypackrambler.co.uk/ramblertrial/compass.php">
    The Compass</a></li>
    <li <?php if ($openpage=="Contours") echo " id=\"currentpage\""; ?>>
    <a href="http://www.daypackrambler.co.uk/ramblertrial/contours.php">
    Contours</a></li>
    <li <?php if ($openpage=="Grid") echo " id=\"currentpage\""; ?>>
    <a href="http://www.daypackrambler.co.uk/ramblertrial/grid-
    references.php">Grid References</a></li></ul>
    </div>

the css is

    .sidebar { position:fixed; width:140px; top:75px; float:left;
    font-family:Verdana, Georgia, Arial, sans-serif; font-size:small;}
    * {margin:2px;}
    nav {width:160px;}
    .navbar {width:160px;}
    .navarrow {float:right; padding-right:10px;}
    .navbar h4, .subbar h4 {font-weight:normal; padding:7px;
    background:url('../general images/navbuttonwalker.png') no-repeat;
    border:1px solid #303030;}
    .navbar h4 a, .subbar h4 a {display:block; text-decoration:none;
    width:130px; padding-left:20px; color:#000}
    .navbar h4 a:hover, .subbar h4 a:hover {color:#fff;}
    .navbar ul, .subbar ul {height:0px; /*Collapses the menu*/
    list-style-type:none; overflow:hidden; padding:0px;
    /*Animation*/-webkit-transition:height 1s ease;
    -moz-transition:height 1s ease; -o-transition:height 1s ease;
    -ms-transition:height 1s ease;
    transition:height 1s ease;}
    .navbar ul a {margin-left:20px; text-decoration:none; display:block;
    width:130px;}
    .navbar:hover ul {height:102px;}
    .navbar li {border:1px solid #303030;
    background:url('../generalimages/navbuttonwalker.png') no-repeat;
    line-height:2; padding-left:20px;}
    .subbar li {height:0px;}
    .navbar li a {color:#000;}
    .navbar li a:hover {color:#fff;}
user3601623
  • 5
  • 1
  • 3