+ Reply to Thread
Page 2 of 2 FirstFirst 1 2
Results 11 to 17 of 17

Thread: Membuat Judul Halaman & Menu Dinamis pada Web Statis

  1. #11
    Poster 1.0 Fadli is on a distinguished road
    Join Date
    Jan 2010
    Posts
    70
    Thanks
    34
    Thanked 1 Time in 1 Post

    Default

    saya coba buat:
    PHP Code:
        <?php
            $here 
    basename($_SERVER['SCRIPT_FILENAME']);
            
    $pages = array('index.php''about.php''contact.php');
            
            
    $current array_search($here$pages) === false  ?  'current'  :  'none';
        
    ?>
        <ul>
           <li class="<?php echo $current?>"><a href="index.php">Home</a></li>
           <li class="<?php echo $current?>"><a href="about.php">About</a></li>
           <li class="<?php echo $current?>"><a href="contact.php">Contact</a></li>
        </ul>
    tapi malah ga bisa mas. dimana salahnya?

  2. #12
    Expert 2.0 galuh82 is on a distinguished road verified galuh82's Avatar
    Join Date
    Jun 2008
    Location
    Cianjur
    Posts
    543
    Thanks
    35
    Thanked 47 Times in 42 Posts

    Default

    pastikan dulu variable $here .. apakah valuenya ada yang sama dengan $pages ..

    tampilkan saja isi $here dulu untuk memastikan
    GaluhWeb Hosting Provider
    USA/IIX Linux H☺sting - Web Design - D☺main Registration - VPS - Dedicated Server
    Galuh Technologies Network ☼ Cianjur ☼ +62263-269120
    Blog PutraGaluh - lamun keyeng pasti pareng

  3. #13
    Poster 1.0 Fadli is on a distinguished road
    Join Date
    Jan 2010
    Posts
    70
    Thanks
    34
    Thanked 1 Time in 1 Post

    Default

    nemu cara lain. navigasinya:
    PHP Code:
            <ul>
                <li <?php if (strpos($_SERVER['PHP_SELF'], 'index.php')) echo 'class="current"';?>><a href="index.php">Home</a></li>
                <li <?php if (strpos($_SERVER['PHP_SELF'], 'about.php')) echo 'class="current"';?>><a href="about.php">About</a></li>
                <li <?php if (strpos($_SERVER['PHP_SELF'], 'contact.php')) echo 'class="current"';?>><a href="contact.php">Contact</a></li>
            </ul>
    di title:
    PHP Code:
    <title><?php
    if (strpos($_SERVER['PHP_SELF'], 'index.php'))
        echo 
    '';
    else if (
    strpos($_SERVER['PHP_SELF'], 'about.php'))
        echo 
    'About >';
    else if (
    strpos($_SERVER['PHP_SELF'], 'contact.php'))
        echo 
    'Contact >';
    ?> <?php echo $title?></title>
    cuma saya masih penasaran, ada cara ga untuk menyingkat scriptnya? kok kayaknya mubazir yah banyak nulis strpos($_SERVER['PHP_SELF'] berulang kali??

    trus dari segi resource apa ini banyak membebani server ga yah??

  4. #14
    Expert 2.0 galuh82 is on a distinguished road verified galuh82's Avatar
    Join Date
    Jun 2008
    Location
    Cianjur
    Posts
    543
    Thanks
    35
    Thanked 47 Times in 42 Posts

    Default

    ya php_self juga bisa, detilnya beberapa variable server bisa dilihat dari phpinfo

    kalo triknya sudah ketemu tinggal anda cari optimasi-nya biar scriptnya lebih singkat
    GaluhWeb Hosting Provider
    USA/IIX Linux H☺sting - Web Design - D☺main Registration - VPS - Dedicated Server
    Galuh Technologies Network ☼ Cianjur ☼ +62263-269120
    Blog PutraGaluh - lamun keyeng pasti pareng

  5. #15
    Poster 1.0 Fadli is on a distinguished road
    Join Date
    Jan 2010
    Posts
    70
    Thanks
    34
    Thanked 1 Time in 1 Post

    Default

    nah itulah yg saya blm ngerti caranya mas..?

  6. #16
    Beginner 1.0 dino is on a distinguished road
    Join Date
    Sep 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    coba dibuat fungsi php aja

    PHP Code:
    <?php
    function current_class(){
        
    $file $_SERVER["SCRIPT_NAME"];
        
        if      (
    $file == '/about.php') { echo ' class="current"'; }
        elseif ( 
    $file == '/contact.php' ) { echo ' class="current"'; }
        else     ( 
    $file == '/index.php' ) { echo ' class="current"'; }

    }
    ?>
    <head>
    <title>HOME</title>
    </head>
    <body>
    <ul>
         <li><a href="index.php" <?php current_class(); ?>>HOME</a></li>
         <li><a href="about.php" <?php current_class(); ?>>About</a></li>
         <li><a href="contact.php" <?php current_class(); ?>>Contact</a></li>
    </ul>  
    </body>

  7. #17
    Beginner 1.0 dino is on a distinguished road
    Join Date
    Sep 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Fadli View Post
    saya coba buat:
    PHP Code:
        <?php
            $here 
    basename($_SERVER['SCRIPT_FILENAME']);
            
    $pages = array('index.php''about.php''contact.php');
            
            
    $current array_search($here$pages) === false  ?  'current'  :  'none';
        
    ?>
        <ul>
           <li class="<?php echo $current?>"><a href="index.php">Home</a></li>
           <li class="<?php echo $current?>"><a href="about.php">About</a></li>
           <li class="<?php echo $current?>"><a href="contact.php">Contact</a></li>
        </ul>
    tapi malah ga bisa mas. dimana salahnya?
    kalo pake kodenya agan ganti
    PHP Code:
     $pages = array('index.php''about.php''contact.php'); 
    dengan

    PHP Code:
     $pages = array('/index.php''/about.php''/contact.php'); 

+ Reply to Thread

Similar Threads

  1. Pilih WEB-Statis atau CMS
    By Michael Nicky in forum Desain Web & Programming
    Replies: 31
    Last Post: 02-Sep-2010, 11:33 AM
  2. bikin mesin pencarian untuk web statis
    By RAY007 in forum Desain Web & Programming
    Replies: 1
    Last Post: 01-Oct-2009, 08:51 AM
  3. Free Webhosting Dinamis
    By piet in forum [IKLAN] Hosting Gratis
    Replies: 1
    Last Post: 10-Jun-2008, 09:34 PM
  4. Perbedaan Description dan Keyword pada Halaman
    By rizkyonline in forum Search Engine & Direktori Web
    Replies: 1
    Last Post: 21-Nov-2007, 01:46 PM

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