Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8442019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:43:53+00:00 2026-06-10T08:43:53+00:00

To start out: Not WordPress! Just plain old PHP. Here’s what I’m trying to

  • 0

To start out: Not WordPress! Just plain old PHP. Here’s what I’m trying to do:

I’ve got a horizontal navigation bar at the top of my page with the links ‘Home, About, Info, Contact’

Most of the pages also have a vertical navigation bar, the sidebar.
If I’m on the Home page, no sidebar needs to be shown.
If I’m on the About page there has to be a sidebar with various other subjects. The Contact page needs to show a sidebar with a Route Description and Contact Form link etc.

I was thinking about achieving this with $GLOBAL variables and put something like $GLOBAL['sidebar] = 'home' $GLOBAL['sidebar'] = 'contact' etc… on top of every page. In the PHP file that would render my sidebar I would use an if structure to see what sidebar needs to be rendered. But using global variables is something I’ve always been taught is wrong and shouldn’t be used. After that, my mind drifted to $SESSION variables, but that would actually be exactly the same but with some extra concerns like session_start() etc.

I’m self-taught in PHP so I don’t know what could be best used to solve this particular (and I presume very common) “issue”. Any insights about this matter would be greatly appreciated. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:43:55+00:00Added an answer on June 10, 2026 at 8:43 am

    The solution will depend a lot on how you’ve set up your code structure already, but in more general terms the way I usually do it is to:

    Include the sidebar as part of your template included on every page.

    Set up your sidebar along the lines of this:

    <?php
    if (sizeof($sidebarModules)>0) {
      ?>
      <div id="sidebar">
      <?php
        if (in_array('contact',$sidebarModules)) {
        // display contact form
      }
      if (in_array('route',$sidebarModules)) {
        // display route description
      }
      if (in_array('login',$sidebarModules)) {
        // display login
      }
      ?>
      <\div>
      <?php
    }
    ?>
    

    Then at the top of each page make sure you define the array $sidebarModules. Something like:

    <?php
      $sidebarModules = array(
        'contact',
        'login',
        'description'
      );
    ?>
    

    I’m not sure if this is the best solution, but it’s worked well for me in the past.

    Edit:

    or do it more efficiently if you’re templates are named in a standard convention, e.g.:

    <?php
    if (sizeof($sidebarModules)>0) {
      ?>
      <div id="sidebar">
      <?php
        foreach ($sidebarModules as $module) { // loop round all modules
          include($module.'_tpl.php'); // include module template
        }
      ?>
      <\div>
      <?php
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First, I'd like to start out expressing that I am not trying to just
I'll just start out by saying I am not at all experienced with creating
Let me start out by saying that I'm not a C developer and I
I'm trying to start out with LinqtoXml. I have added (I think) the right
Just want to start out by saying this seems like a great site, hope
Okay I do apologise that I'm out of my depth here. I'm not the
I am trying to layout a bunch of overlapping rectangles that start out like
To start out here is a simplified version of the tables involved. tbl_map has
Let me start out by saying that I'm not a JavaScript developer so this
Let me just start out by saying I am completely new to Java web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.