Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 01-03-2011, 12:00 PM menu
webmaster flex's Avatar
Extreme Talker

Posts: 160
Name: Webmaster flex
Trades: 0
hi, ive just been learning abit of php and wanted to convert my menu to php so incase i wanted to add, change or remove a menu item i wouldent have to edit each individual file that contains it. i realise i could do this using an include file, but then it would only show the menu and not have the current pages tab highlighted.

how would i convert the menu to php but when on a page eg www.mypage.com/about the "about" tab on the menu would be selected as normal

regards, flex
webmaster flex is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-03-2011, 04:22 PM Re: menu
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
You can use the include file to output the HTML for the menu according to a function call on the pages like display_menu("about") - if you only have a few pages this is easiest. Keep an array of your pages and associated parameter to the function call and output appropriate php.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Old 01-09-2011, 09:28 AM Re: menu
webmaster flex's Avatar
Extreme Talker

Posts: 160
Name: Webmaster flex
Trades: 0
would you be able to run me through this in abit more detail please im still learning

regards
webmaster flex is offline
Reply With Quote
View Public Profile
 
Old 01-17-2011, 02:41 AM Re: menu
Html Web Design's Avatar
Experienced Talker

Posts: 31
Name: WP Themes
Location: Nagpur
Trades: 0
You can try this code which helps you
Code:
<?php

    // The menu bar is built from the array below.  Since the HTML generation
    // code is recursive, depth is unlimited.  Syntax should be fairly obvious
    // from the current array.
    //
    // TODO: either get the heading from the page or set it there -- having it
    // in two different places doesn't make sense, although an override might.
    $pageArray = array(
        "Home" => "/index.php",
        "Bio of a random hacker" => "/bio.php",
        "Contact details" => "/contact.php",
        "Licensing" => "/licensing.php",
        "Webcomics" => "/comics.php",
        "Other people" => "/people.php",
        "Code" => array(
            "Python random name generator" => "/code/cfnamegencode.php",
            "PHP syntax highlighter" => "/code/syntaxhlcode.php",
            "PHP menu generator" => "/code/phpmenucode.php",
            "xmms sleep script" => "/code/xmmssleepcode.php",
            "irssi channel beeping script" => "/code/irssichanbeep.php",
            "Python logfile reader class" => "/code/logfile.php",
            "Home directory analysis script" => "/code/homediranalysis.php",
            "Remote execution script" => "/code/remoteexec.php",
            "Dialup control panel" => "/code/dialupcp.php",
            "Hamming number calculator" => "/code/hammingnums.php",
            "PHP python datatype parser" => "/code/pythontypes.php",
            "Python TOC generator" => "/code/maketoc.php",
        ),
        "Shiny stuff" => array(
            "Campus proxy squid hack" => "/shiny/proxyserver.php",
            "Phone stuff" => "/shiny/phone.php",
        ),
        "Writings" => array(
            "How to send an electronic notice" => "/writings/notice-netiquette.php",
            "How to survive Computer Methods pracs" => "/writings/howtosurvivecm.php",
            "How not to cheat" => "/writings/hownottocheat.php",
            "Linux for computer scientists" => "/writings/linuxforcompsci.php",
            "Teach yourself programming" => "/writings/learnprogramming.php",
        ),
    );

    function iecho($indent, $text) {
        // Indents the HTML for the menu -- purely making the code look
        // pretty, no effect on rendering.
        for ($i=0; $i<$indent; $i++) {
            echo "\t";
        }
        echo $text;
    }

    function isNew($url) {
        $url = "base" . $url;
        if (filemtime($url)) {
            if (time() - filemtime($url) < 604800) { // 604800 secs in a week
                return true;
            }
        }
        return false;
    }

    function isAbsolute($url) {
        if (strpos($url, "://") != false) {
            return true;
        } else {
            return false;
        }
    }

    function navGen($pageArray) {
        // Takes the array given in $pageArray and generates the navigation
        // bar from it.
        //
        // TODO: Finish the version that handles authentication, etc. and put
        // that here.
        static $indent = 1;

        $currentFile = get_included_files();
        $currentFile = basename($currentFile[0]);

        iecho($indent, "<ul>\n");
        $indent += 1;
        foreach ($pageArray as $name => $url) {
            if (is_array($url)) {
                iecho($indent, "<li>$name\n");
                navGen($url);
                iecho($indent, "</li>\n");
            } else {
                // Is this the current page?
                if ($url == $currentFile) {
                    $class = " class=\"navcurrent\"";
                } else {
                    $class = "";
                }
                // Is this page external?
                if (isAbsolute($url)) {
                    // If so, mark it as such.
                    $icon = "<img src=\"common/external.png\" alt=\"external\" />";
                } else {
                    // If it's local, we can check for newness.
                    if (isNew($url)) {
                        $icon = "<img src=\"common/new.png\" alt=\"new\" />";
                    } else {
                        $icon = "";
                    }
                }
                iecho($indent, "<li>".$icon.
                                "<a$class href=\"$url\">$name</a></li>\n");
            }
        }
        $indent -= 1;
        iecho($indent, "</ul>\n");
    }

?>
<div id="navbar">
<h1>jerith.za.net</h1>
<?php navGen($pageArray); ?>
</div>
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
Html Web Design is offline
Reply With Quote
View Public Profile Visit Html Web Design's homepage!
 
Reply     « Reply to menu
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13183 seconds with 12 queries