Home Footer or Menu Link Unit from a PHP Array

    Footer or Menu Link Unit from a PHP Array

    0

    This post will show you how to build a string of links from an array using PHP.

    In our Internoetics downtime, we would have put together about 70 or so of our own (mostly crappy) websites. For virtually all of the sites that we built, we had a simple configuration file that contained global variables meaning that we could quickly and easily effect site changes. That included using user-defined arrays to generate header and footer menus.

    The Output

    Here’s a snapshot from one of the site that utilises similar code. The footer menu is in the bottom right of the image. Simple, right?

    Menu link array PHP

    Menu Links Generated from Array

    The Code

    Usage

    Use the function as follows:

    echo beliefmedia_footer_links();

    The HTML that’s generated would output as follows:

    Home | Internoetics | Flight | BeliefMedia

    We use a pipe separator by default, but if you wanted to change that to say, double colons, simply use the function as follows:

    echo beliefmedia_footer_links($sep = ' :: ');

    This time, the generate HTML would output as follows:

    Home :: Internoetics :: Flight :: BeliefMedia

    Keeping the Array in a Functions File

    If you sensibly include your functions in its own file and include the array in a configuration file, remember to add global $footerLinks; so the array is available inside the function.

    Shortt URL for this post: http://shor.tt/1XI3