SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Perth W.A.
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating a class on the fly

    Hi Guys,
    I wish to display the current page menu item in a different colour to show visitors they are on this page.

    It think it requires creating a class on-the-fly as the particular page loads, using the _GET() super global as follows: (but I don't know what to get and from where!)

    Code PHP:
    //This:
     
    <?php if($this->item->params->get('itemTitle')): ?>
    * * *<!-- Item title -->
    * * *<h2 class="itemTitle <?php echo 'catitem'.$_GET['Itemid'];?>">
     
    //produces this:
     
    	  <!-- Item title -->
    	  <h2 class="itemTitle catitem4">
    	  	Parnngurr Carnival Football
     
    	  </h2>

    The above code is taken from one of my Joomla sites, which allows me to style the page independently of the others, however I want this to happen on a hand coded site I'm building.

    I have an include function calling my top navigation code for all pages. Do I invoke the $_get() from within the relevant li tags as follows:

    Any help appreciated.
    Code PHP:
    <link href="css/menu-style.css" rel="stylesheet" type="text/css" />
      <div id="top">
        <ul>
          <li class="<?php echo 'current'.$_GET()?>"><a href="index.php">Home</a> </li>
          <li><a href="brochures_posters.php" >Graphic Design</a>
            <!--<ul>
              <li><a href="brochures_posters.php">Brochures and Posters</a></li>
              <li><a href="logos.php">Logos</a></li>
              <li><a href="corp_id.php">Corporate Identity</a></li>
              <li><a href="signage.php">Signage</a></li>
              <li><a href="printing.php">Printing</a></li>
              <li><a href="photography.php">PHotography</a></li>
              <li><a href="print-services/advertising.php">Advertising</a></li>
              <li><a href="copywriting.php">Copy Writing</a></li>
            </ul>-->
          </li>
          <li class="<?php echo 'current'.$_GET()?>"><a href="#">Web Design</a>
            <!--<ul>
              <li><a href="http://domains.webdesignperth.com.au/system/home/home/">Domain Registration</a></li>
              <li><a href="web-design/web-hosting.php">Web Hosting</a></li>
              <li><a href="web-design/search-engine-optimization.php">SEO</a></li>
              <li><a href="web-design/search-engine-marketing.php">SEM</a></li>
            </ul>-->
          </li>
          <li class="<?php echo 'current'.$_GET()?>"><a href="#">Handy Hints</a>
            <!--<ul>
              <li><a href="print_tips.php">On Print Design</a></li>
              <li><a href="web_hints.php">On Web Design</a></li>
              <li><a href="how.php">How We Work</a></li>
              <li><a href="copywriting.php">Copywriting</a></li>
              <li><a href="how.php#resources">Resources</a></li>
              <li><a href="http://www.wikihow.com/Take-a-Screenshot-in-Microsoft-Windows">Print your screen</a></li>
            </ul>-->
          </li>
          <li class="<?php echo 'current'.$_GET()?>"><a href="#">About us</a>
            <!--<ul>
              <li><a href="testimonials.php">Testimonials</a></li>
              <li><a href="faq.php">F.A.Q.</a></li>
            </ul>-->
          </li>
          <li class="<?php echo 'current'.$_GET()?>"><a href="sitemap.html">Site Map</a></li>
          <li class="<?php echo 'current'.$_GET()?>"><a href="contact-us.php">Contact Us</a></li>
        </ul>
      </div>

  2. #2
    Non-Member
    Join Date
    Apr 2011
    Location
    no fixed address
    Posts
    851
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is a common question and you can do it relatively easily using just plain html and css without having to create anything on the fly.

    There are lots of tute's on the www showing how. This is one tute showing the The Body ID / Class method or another tute.

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Perth W.A.
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Many thanks!
    That seems like a much easier option than php.


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
  •