Zikula: A Flexible Open Source Content Management System
home | forum | contact us

Dizkus

Bottom
User friendly theme links
  • Posted: 08.08.2003, 17:29
     
    Lobos
    rank:
    Professional Professional
    registered:
     December 2002
    Status:
    offline
    last visit:
    24.08.08
    Posts:
    1588
    Greetings,

    More often these day's I am noticing that themers are coding buttons and links directly into the theme - it's nice to see because the generic menu is soooooo boring! The trouble is this can be a nightmare to update if you are not familiar with HTML or PHP or whatever.

    The issue is addressed somewhat with top and bottom links defined in the lang file of some of the core themes, but this is not good enough - what if you want to add more?

    My solution to this is to dynamically build the links (or link menu) using an array. Enough rambling let's do it.

    Create a file called themes/yourtheme/lang/eng/linkConfig.php and include the folowing code:

    Code

    <?php
    //Items for menu buttons in header - add new lines when required.

    $topnav = array (
    "Home"       => "index.php",
    "Articles"    => "modules.php?op=modload&name=Topics&file=index",
    "Sections"    => "modules.php?op=modload&name=Sections&file=index",
    "Downloads"=> "modules.php?op=modload&name=Downloads&file=index",
    "Forum"   => "modules.php?op=modload&name=XForum&file=index",
    "FAQ"     => "modules.php?op=modload&name=FAQ&file=index"
    //remember there is no comma on the last line!!!
    );

    ?>


    This is the config file and you can add more links as required because the "while loop" will include them all .

    You add the following code to your theme.php file (or what ever template you want it to display on)

    Code

    <?php

    //Link builder by Lobos
    //Don't touch this code! Edit linkConfig.php in the lang folder :)

    // Get the langauge variable and include the correct array      
    $currentlang = pnUserGetLang();
    include $themepath."lang/".$currentlang."/linkConfig.php";  
       while (list ($key, $value) = each ($topnav))
       
       echo"<a href=\""
             .$value
             ."\">"
             .$key
             ."</a>&nbsp|&nbsp \n";
       
    ?>

    See how the $key and $value variables are taken from the file in the lang folder.
    This is a very basic way of doing this and will make for a very boring menu... good for footer links though. The code will render like this:

    Code

    <a href="index.php">Home</a>&nbsp|&nbsp
    <a href="modules.php?op=modload&name=Topics&file=index">Articles</a>&nbsp|&nbsp
    And so on and so on

    Like I was saying this is very boring so below I have included the loop I use to build the button menu in my latest theme wvCorporateX:

    Code

    <?php
    //Link builder by Lobos
    //Don't touch this code! Edit linkConfig.php in the lang folder :)

    $currentlang = pnUserGetLang();
    include $themepath."lang/".$currentlang."/navbar.php";

    while (list ($key, $value) = each ($topnav))
         echo"<td style=\"padding-left: 0px; padding-bottom: 0px; padding-top: 6px; background-image:url($imgpath/wvButton.jpg);\" width=\"92\" align=\"center\" height=\"28\" valign=\"middle\">  \n"     
            ."<font class=\"wvMCblockTitle\"><a href=\""
        .$value
        ."\">"
        .$key
        ."</a></font></td> \n";
             
    ?>

    A lot more complex and layout breakage could occur with too many links, but you should get the idea of the potential of this tasty bit of code. You can add as many of these as you want all you have to change is the "each variable" eg:

    Code

    while (list ($key, $value) = each ($topnav))

    to

    Code

    while (list ($key, $value) = each ($bottomnav))

    and in the linkConfig.php change

    Code

    $topnav = array (

    to

    Code

    $bottomnav = array (


    It is now easy (or fairly easy) for people with no html/php knowledge to update there theme links. You can do a lot with this: I used it to make the popup menus at webvida.com very easy to update and now I don't need to wade through heeps of javascript when I want to change things!

    Kindest regards
    Lobos

    --
    -Lobos
    Professional PHP Framework Services: Concept, Development and Deployment
  • Posted: 09.06.2005, 16:10
     
    Zex_Suik
    rank:
    Freshman Freshman
    registered:
     July 2002
    Status:
    offline
    last visit:
    20.08.06
    Posts:
    38
    Hey Lobos,

    I found your post very helpful. I'm starting to learn PHP so I tried expanding your code to make two sets of links depending on login status. I left out the button making code so a newbie can cut and paste without worrying about the buttons yet. Of course a moderate user can figure out the button use on their own.

    Thanks for the help!

    Code

    <!-- This row displays the links based on access -->
                                <tr>
                                    <td align="center">
                                    |&nbsp
                                        <?
    /* I modified this so you can set two sets of links for loggedin and logged out people*/
    /* There are two arrays here amke sure you edit the links in each */
    /* I put everything together to make it easier for you to use */
    /* originally from Lobos
    http://forums.postnuke.com/index.php?name=PNphpBB2&file=viewtopic&t=15061&highlight=user+friendly
    */


    /* For logged in users */
    //Items for menu buttons in header - add new lines when required.
    $drloggedoutlinks = array (
    "Home"            => "index.php",
    "Directory"       => "/index.php?name=BizPages",
    "Forum"           => "/index.php?name=PNphpBB2",
    "Search"          => "/index.php?name=Search",
    "Register - Free" => "/user.php"
    //remember there is no comma on the last line!!!
    );

    /* For logged out users */
    //Items for menu buttons in header - add new lines when required.
    $drloggedinlinks = array (
    "Home"             => "index.php",
    "My Account"       => "user.php",
    "Directory"        => "/index.php?name=BizPages",
    "Forum"            => "/index.php?name=PNphpBB2",
    "Search"           => "/index.php?name=Search",
    "Submit an Article" => "/index.php?name=Submit_News"
    //remember there is no comma on the last line!!!
    );
    if (!pnUserLoggedIn())
            {
                while (list ($key, $value) = each ($drloggedoutlinks))

                   echo"<a href=\""
                         .$value
                         ."\">"
                         .$key
                         ."</a>&nbsp|&nbsp \n";
            }
            else
            {
                while (list ($key, $value) = each ($drloggedinlinks))

                   echo"<a href=\""
                         .$value
                         ."\">"
                         .$key
                         ."</a>&nbsp|&nbsp \n";
            }
    /* this is for the admin link */
                         if (pnSecAuthAction(0, '::', '::', ACCESS_ADMIN))
                            {
                            ?><a href="/admin.php">Admin</a><?
                            }

        ?>


    --
    www.DesRat.com

Main Menu

Extensions Database

Documentation

Development

Login

Donate to Zikula