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 9106333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:18:51+00:00 2026-06-17T02:18:51+00:00

I have the following code to include pages dynamically: <div id=content> <div id=aside> …

  • 0

I have the following code to include pages dynamically:

<div id="content">
    <div id="aside">
        ...
    </div>

    <div id="main">
        <?php
        $page = (isset($_GET['page'])) ? sanitize($_GET['page']) : 'home';
        if (!include 'pages/'.$page.'.php') require 'pages/404.php';
        ?>
    </div>
</div>

As you can see, the #aside has static content.
I want to include a specific content for the #aside depending on the page selected. For example, if the user goes to ‘Home’ and ‘About’, I want the ‘default’ aside. But if the user goes to ‘Documents’ I want a ‘Sections’ aside.
I know I can just include each aside from every page, but that’s not effective. I also don’t want the user to be hable to set the aside as the main content, so they have to be in different folders or something.
I’d like to know an effective and not so complicated way to do this.

Thanks for taking your time to read this.

  • 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-17T02:18:52+00:00Added an answer on June 17, 2026 at 2:18 am

    Thank you all for your answers and collaboration. Although none of the answers did exactly what I was looking for, they showed me other ways to approach this issue and guided me to decide what method to use.
    I came up with what I think is the simpliest way to do this:

    1. I set my folder structure as: pages/aside and pages/main
    2. I set up an array($asides) with the aside files as the keys and the main content files as the values.
    3. Then I check if the requested file exists in the main folder.
    4. If it doesn’t exist, I redirect the user to the 404 page. If it does exist, I loop through $asides to see which aside is asigned to that main content page.
    5. If it doesn’t belong to any of the establisged asides, then I include the default aside.
    $asides = array(
            'aside1' => array('page1', 'page2', 'page3', 'page4'),
            'aside2' => array('page5', 'page6')
        );
    
    $page = (!empty($_GET['p'])) ? sanitize($_GET['p']) : 'page1';
    
    if (file_exists("pages/main/{$page}.php")) {
    
        foreach ($asides as $key => $value) {
            if (in_array($page, $asides[$key])) {
                $aside = $key;
                break;
            }
        }
        if (!isset($aside)) $aside = 'default';
    
    ?>
        <div id="aside"><?php require "pages/aside/{$aside}.php"; ?></div>
        <div id="main"><?php require "pages/main/{$page}.php"; ?></div>
    <?php
    
    } else {
        header('Location: ?p=404');
    }
    

    The bounty goes to Madara Uchiha because in my opinion, his answer is simple an effective. Thanks again to all of you who helped me with this issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following PHP code: //switch if (isset($_GET['pg'])) $pg = $_GET['pg']; else{ $pg
i have the following code: #include <stdio.h> int main(void) { float a[4] __attribute__((aligned(0x1000))) =
I have the following code: #include <string.h> int main(void) { char *buffer = NULL,
I have a following code: <?php include(config.php); $key = 'blahblah'; $sql = INSERT INTO
Hello in my aspx page using MVC 3, I have the following code: <%Response.WriteFile(/Content/Bing.htm);
I have the following code: #include<iostream> using namespace std; typedef void (*HandlerFunc)(int, int); HandlerFunc
I have the following code: #include <stdio.h> #include <pthread.h> #define THREAD_CNT 10 #define ITER
I have the following code: #include <iostream> #define BOOST_TEST_MODULE my test #include <boost/test/unit_test.hpp> BOOST_AUTO_TEST_CASE(
I have the following code: #include <iostream> #include boost/shared_ptr.hpp using boost::shared_ptr; class Base {
I have the following code: #include <boost/shared_ptr.hpp> struct Foo { int a; }; static

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.