Jump to content

Recommended Posts

I have an index.php file which displays my sites dynamic header,footer, and sidebar. I would like to remove the sidebar on somepages but I am lost. I am very very new to php and know little. Below is my index.php file.

 

 

 

<?php 
$default = 'inc/home.php'; 
if ($handle = opendir('inc')) { 
    while (false !== ($file = readdir($handle))) { 
        if ($file != "." && $file != "..") { 
            $pages[basename($file,'.php')] = 'inc/'.$file; 
        } 
    } 
    closedir($handle); 
} 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 
<style type="text/css"> 







/* 
Design by Free CSS Templates 
http://www.freecsstemplates.org 
Released for free under a Creative Commons Attribution 2.5 License 
*/ 

body { 
    margin: 20px; 
    background: #000000; 
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; 
    font-size: 13px; 
    color: #787878; 
} 

h1, h2, h3 { 
    margin: 0; 
    font-family: Georgia, "Times New Roman", Times, serif; 
    font-weight: normal; 
    color: #000000; 
} 

h1 { 
    font-size: 2em; 
} 

h2 { 
    font-size: 1.6em; 
} 

h3 { 
    font-size: 1.6em; 
} 

p, ul, ol { 
    margin-top: 0; 
    line-height: 180%; 
} 

ul, ol { 
} 

a { 
    text-decoration: none; 
    border-bottom: 1px dotted #999999; 
    color: #A42424; 
} 

a:hover { 
    background: none; 
} 

#wrapper { 
    width: 910px; 
    margin: 0 auto; 
    padding: 20px; 
    background: #FFFFFF; 
} 

/* Header */ 

#header { 
    width: 910px; 
    height: 172px; 
    margin: 0 auto; 
    background: url(images/img01.jpg) no-repeat left top; 
} 

/* Logo */ 

#logo { 
    float: left; 
    width: 640px; 
    color: #B2B2B2; 
} 

#logo h1, #logo p { 
} 

#logo h1 { 
    float: left; 
    padding: 125px 0 0 800px; 
    letter-spacing: 0px; 
    text-transform: uppercase; 
    font-size: 2.6em; 
         background: url(http://govbuzz.com/images/header-logo-1.png) no-repeat left top; 
} 

#logo p { 
    float: left; 
    margin: 0; 
    padding: 110px 0 0 5px; 
    text-transform: uppercase; 
    font: bold 14px Arial, Helvetica, sans-serif;     
}  

#logo a { 
    border: none; 
    background: none; 
    text-decoration: none; 
    color: #FFFFFF; 
} 

/* Search */ 

#search { 
    float: right; 
    width: 230px; 
    padding-top: 0px; 
} 

#search form { 
    height: 41px; 
    margin: 0; 
    padding: 0px 0 0 0px; 
} 

#search fieldset { 
    margin: 0; 
    padding: 0; 
    border: none; 
} 

#search-text { 
    width: 200px; 
    border: none; 
    text-transform: lowercase; 
    border: 1px #525252 dotted; 
    font: bold 1.2em Arial, Helvetica, sans-serif; 
    color: #FFFFFF; 
} 

#search-submit { 
    display: right; 
} 

/* Menu */ 

#menu { 
    width: 910px; 
    height: 41px; 
    margin: 0 auto; 
    padding: 0; 
    background: url(images/img02.jpg) no-repeat left top; 
} 

#menu ul { 
    margin: 0; 
    padding: 0; 
    list-style: none; 
    line-height: normal; 
} 

#menu li { 
    float: left; 
} 

#menu a { 
    display: block; 
    padding: 13px 10px 10px 20px; 
    text-transform: uppercase; 
    text-decoration: none; 
    font-family: Arial, Helvetica, sans-serif; 
    font-size: 10px; 
    font-weight: bold; 
    color: #FFFFFF; 
    border: none; 
} 

#menu a:hover, #menu .current_page_item a { 
    color: #FFFFFF; 
} 

#menu a:hover { 
    text-decoration: underline; 
} 

/* Page */ 

#page { 
    width: 910px; 
    margin: 0 auto; 
    background: url(images/img03.jpg) no-repeat left top; 
         color: #000000; 
} 

/* Content */ 

#content { 
    float: left; 
    width: 600px; 
    padding: 40px 0 0 20px; 
} 

.post { 
} 

.post .title { 
    color: #000000; 
} 

.post .title a { 
    background: none; 
    color: #ffffff; 
    border: none; 
} 

.post .title a:hover { 
    text-decoration: underline; 
} 

.post .meta { 
    border-bottom: 1px dashed #D2D4C9; 
    text-transform: uppercase; 
    text-align: left; 
    font-family: Arial, Helvetica, sans-serif; 
    font-size: 9px; 
} 

.post .entry { 
    padding: 10px 0 20px 0; 
    text-align: justify; 
} 

/* Sidebar */ 

#sidebar { 
    float: right; 
    width: 220px; 
    padding: 40px 20px 0 0; 
    color: #787878; 
} 

#sidebar ul { 
    margin: 0; 
    padding: 0; 
    list-style: none; 
} 

#sidebar li { 
} 

#sidebar li ul { 
    padding-bottom: 30px; 
} 

#sidebar li li { 
    line-height: 35px; 
    border-bottom: 1px dashed #D2D4C9; 
} 

#sidebar h2 { 
    letter-spacing: -.5px; 
    color: #000000; 
} 

#sidebar p { 
    padding-bottom: 20px; 
    text-align: justify; 
} 

#sidebar a { 
    color: #787878; 
    border: none; 
} 

#sidebar a:hover { 
    text-decoration: underline; 
    color: #787878; 
} 

/* Calendar */ 

#calendar { 
} 

#calendar_wrap { 
    padding: 20px; 
} 

#calendar table { 
    width: 100%; 
} 

#calendar tbody td { 
    text-align: center; 
} 

#calendar #next { 
    text-align: right; 
} 

/* Footer */ 

#footer { 
    width: 910px; 
    height: 50px; 
    margin: 0 auto; 
    padding: 40px 0; 
    font-family: Arial, Helvetica, sans-serif; 
    color: #B2B2B2; 
} 

#footer p { 
    margin: 0; 
    line-height: normal; 
    font-size: 9px; 
    text-transform: uppercase; 
    text-align: center; 
} 

#footer a { 
    color: #FFFFFF; 
} 
} 











</style> 
</head> 
<body> 





<div id="wrapper"> 
    <div id="header"> 
        <div id="logo"><br> 
<h1></h1> 

             
        </div> 

<div id="search"><br><br> 
<a href="http://govbuzz.com/index.php?page=howtouse"><img src="http://govbuzz.com/images/arrow2.png" border="0"></a> 
            <form action="/SearchEngine/search.pl" method="get"><br><br> 


<input type="text" name="q" /><input type="submit" value="Search" /><br><br><input type="hidden" name="p" value="1" /><br><inputtype="hidden" name="lang" value="en" /><br> <input type="hidden"name="include" value="" /><br> <input type="hidden" name="exclude"value="" /><br> <input type="hidden" name="penalty" value="0" /><br></form> </div> 



        <!-- end #search --> 
    </div> 
    <!-- end #header --> 
    <div id="menu"> 
        <ul> 
                           <li><a href="http://govbuzz.com/index.php?page=post"><img src="http://govbuzz.com/images/post.gif" border="0"></a></li>     
            <li><a href="http://govbuzz.com/index.php?page=home">Home</a></li> 
            <li><a href="http://govbuzz.com/index.php?page=media">Media</a></li> 
                           <li><a href="http://govbuzz.com/index.php?page=howtouse">How To Use</a></li> 
             
                           <li><a href="http://govbuzz.com/index.php?page=advertise">Advertise with us</a></li> 
            <li><a href="http://govbuzz.com/index.php?page=contact">Contact</a></li> 
                            
                                
</ul> 
    </div> 
    <!-- end #menu --> 
     


















<div id="page"> 
<div id="content"> 


<?php 
    if(@array_key_exists($_GET['page'], $pages) ) 
    { 
        foreach($pages as $pageid => $pagename) 
        { 
            if($_GET['page'] == $pageid && file_exists($pagename)) 
            { 
                /* if somebody's making a request for ?page=xxx and 
                the page exists in the $pages array, we display it 
                checking first it also exists as a page on the server */ 
                include $pagename; 
              } 
           } // end foreach 
    } 
    else 
    { 
        /* if the page isn't listed in $pages, or there's no ?page=xxx request 
        we show the default page, again we'll also just make sure it exists as a file 
        on the server */ 
        if(file_exists($default)) include $default; 
} 

    ?> 
</div> 






<div id="sidebar"> 
            <ul> 
                <li> 
                    <h2>Note To Officials</h2> 
                    <p> 
<img src="http://govbuzz.com/images/note.png"> 

  </p> 
                </li> 
                <li> 
                    <h2>Categories</h2> 
                    <ul> 
<li><a href="http://govbuzz.com/post.html">Post and Comment Here</a></li> 
<li><a href="http://govbuzz.com/classifieds.html">Classifieds</a></li> 
<li><a href="http://govbuzz.com/jobs.html">Employment</a></li> 
<li><a href="http://govbuzz.com/weather.html">Al Weather</a></li> 
<li><a href="http://govbuzz.com/government.html">Government Resources</a></li> 
                    </ul> 
                </li> 
                <li> 
                    <h2>Blogroll</h2> 
                    <ul> 
                        <li><a href="#">Uncategorized</a> (3) </li> 
                        <li><a href="#">Lorem Ipsum</a> (42) </li> 
                        <li><a href="#">Urna Congue Rutrum</a> (28) </li> 
                        <li><a href="#">Augue Praesent</a> (55) </li> 
                        <li><a href="#">Vivamus Fermentum</a> (13) </li> 
                    </ul> 
                </li> 
                <li> 
                    <h2>Archives</h2> 
                    <ul> 
                        <li><a href="#">December 2007</a> (29)</li> 
                        <li><a href="#">November 2007</a> (30)</li> 
                        <li><a href="#">October 2007</a> (31)</li> 
                        <li><a href="#">September 2007</a> (30)</li> 
                    </ul> 
                </li> 
            </ul> 
        </div> 
        <!-- end #sidebar --> 
        <div style="clear: both;"> </div> 
    </div> 
    <!-- end #page --> 
</div> 







<div id="footer"> 
    <p>Copyright (c) 2009 Govbuzz.com. All rights reserved. </p> 
</div> 



</div> 
</body> 
</html> 

Link to comment
https://forums.phpfreaks.com/topic/171217-remove-css-side-bar-from-some-pages/
Share on other sites

Technically this is not a PHP issue but a HTML one

the sidebar is this code, (see below) remove that and the sidebar will be removed

 

EDIT:

However you say remove it on some pages..do you have a list of pages you want to remove it from ?

a little more info would help

<div id="sidebar">
            <ul>
                <li>
                    <h2>Note To Officials</h2>
                    <p>
<img src="http://govbuzz.com/images/note.png">

  </p>
                </li>
                <li>
                    <h2>Categories</h2>
                    <ul>
<li><a href="http://govbuzz.com/post.html">Post and Comment Here</a></li>
<li><a href="http://govbuzz.com/classifieds.html">Classifieds</a></li>
<li><a href="http://govbuzz.com/jobs.html">Employment</a></li>
<li><a href="http://govbuzz.com/weather.html">Al Weather</a></li>
<li><a href="http://govbuzz.com/government.html">Government Resources</a></li>
                    </ul>
                </li>
                <li>
                    <h2>Blogroll</h2>
                    <ul>
                        <li><a href="#">Uncategorized</a> (3) </li>
                        <li><a href="#">Lorem Ipsum</a> (42) </li>
                        <li><a href="#">Urna Congue Rutrum</a> (28) </li>
                        <li><a href="#">Augue Praesent</a> (55) </li>
                        <li><a href="#">Vivamus Fermentum</a> (13) </li>
                    </ul>
                </li>
                <li>
                    <h2>Archives</h2>
                    <ul>
                        <li><a href="#">December 2007</a> (29)</li>
                        <li><a href="#">November 2007</a> (30)</li>
                        <li><a href="#">October 2007</a> (31)</li>
                        <li><a href="#">September 2007</a> (30)</li>
                    </ul>
                </li>
            </ul>
        </div>
        <!-- end #sidebar -->
        <div style="clear: both;"> </div>
    </div>
    <!-- end #page -->
</div>

 

Its right at the bottom, just before

<div id="footer">
    <p>Copyright (c) 2009 Govbuzz.com. All rights reserved. </p>
</div>
</div>
</body>
</html> 

Thanks for the reply. I know if i remove the  sidebar from index.php it will be gone, however I have will have near 50 pages where the sidebar will need to stay intact. For example, on my home page http://govbuzz.com/  you see the full sidebar. When a visitor visits his specific city (its a state discussion board) I would like to change the side bar to fit the needs of that specific town/city, ie advertisements, city info, or whatever. I thought that if remove the sidebar from these pages (city pages ect.) I could just build a table and place the info I need where the sidebar would be.

 

http://govbuzz.com/index.php?page=362641

(click general discussions on this page)

 

You see where I'm goin?

 

 

In your code, you may want to impliment a trigger. such as ...

if (!isset($_GET['nosb'])) { 
   echo sidebar stuff
}

So http://govbuzz.com/index.php?page=362641&nosb=1 would not place the sidebar within the code, I've actually used this method as it's simpler than the rest.... I'm sure i've seen other sites use tricks such as this, for ease of implimentation.

okay oni-kun suggestion is correct but using $_GET may not be the best solution in this set-up,

 

So try this (i assume by default you want to SHOW the sidebar)

 

above the sidebar add

<?php
if(empty($hidesidebar))
{
?>

 

and below it add

<?php
}
?>

 

Now when you load the page nothing has changed  ::)

So now we want to hide the sidebar on some pages..

Now go to http://govbuzz.com/index.php?page=howtouse

and your see the sidebar, Now open the howtouse.php file in the inc folder and add

<?php
$hidesidebar = true;
?>

Now reload the howtouse page and the sidebar should be gone :)

Rinse and repeat with any other files in the inc folder

Some info (may help)

 

The code you added to the index file, created an IF block around the sidebar HTML code, if the condition of that if statement is true then it processes what's in the block (as theirs only HTML in it it displays it)

 

The condition

empty($hidesidebar)

checks to see if $hidesidebar is empty (blank/false/unset/0 etc)

if $hidesidebar is empty then it will display the HTML but when you set $hidesidebar = true; the IF condition is false (not empty) thus doesn't display the HTML,

Remember if you DON'T set $hidesidebar its classed as empty

 

Now that's fine but how does index know a value from another file ?

 

the code at the start builds an array for all files in the INC folder called $pages

 

then about half way down your see that

the code checks to see if value of $_GET['page'] is in the $pages array.. if it is then it include the file

note: $_GET['page'] is the part of the URL ?page=whatever

 

NOW this is important the file is included BEFORE the sidebar thus $hidesidebar is also included before the if statement

 

If this is solved please click the topic solved button bottom left

Well, I tried to place a table in my pages where I removed the sidebar. Its not going to work and I think it may have somthing to do with your recent reply. The sidebar is just empty and not gone from what I understand and that is fine. I now need to figure out how to replace the sidebar info (html) with different html settings to fit that specific page.....UUHUHUHUH.

 

Im still going over what you said in your recent post. Once again, I'm tryin.... :confused:

Sorry I'm not great at explaining things at the best of times.

the side bar never gets processed which means it doesn't exist when $hidesidebar is not empty ($hidesidebar = true;)

 

When you open the page and theirs an if statement if the condition is false the code skips what's in the block

ie

if(false)
{
//this is skipped
}

the only difference  in your code is you have HTML but the same logic applies

<?php
if(false)
{
?>
//this is skipped
<?php
}
?>

 

Now ANYTHING in the files in the INC folder will be placed in side the <div id="content">

 

Now if you want different side bars for different pages we can work to that ..

what's your ideal set-up ? you final goal / requirements ?

 

Well here it is. The site is obviously going to be used for discussions of local governement issues. In the post and comment page you will see that I have many different counties and cities to choose from. Within these cities or counties visitors will have the options of different discussion boards (http://govbuzz.com/index.php?page=36264). Now to someone like yourself, I probably wasted space telling you that, Im sure you could figure it out. However, within the city and county pages I would like the sidebar to display specific information about that intity to include advertisements(http://govbuzz.com/images/saidebarsamp.bmp). Hundreds of pages and hundreds of different sidebars. Hope I answered your question.

 

 

Final goals: Once i determine how to format these specific sidebars, iwill creat the different forums and hopefully thats it. I would like to keep the site simple. I have been building this site for aroung 18 days now and I know nothing of building sites up to this point.

I think it maybe an idea to move to a database driven site (example at the bottom),

Keeping with the current theme, if you want different sidebars then i think it maybe an idea to create a sidebar with a name close to the page its used on, for example "howtouse" side bar would be "howtouse-side"

 

then we can replace the whole sidebar and if statement with

 

<?php
/*Probably want to secure this a little better first*/
$sidebar = $_GET['page']."-side.php";
if(file_exists($sidebar))
{
  include $sidebar;
}
?>

 

 

Database driven

Have 2 tables Pages & Sidebars

 

Pages will have the following fields

uID - auto number field

Name - page name (ie howtouse)

Contents or Filename - HTML contents

SidebarID - the ID of the sidebar 0=no sidebar

 

Sidebars will have the following fields

uID - auto number field (also used by SidebarID in Pages)

Contents or Filename

 

Now you can use a Query to check for contents and sidebar

ie (you could use a JOIN but i am trying to keep it simple

$SQL = sprintf("SELECT * FROM Contents WHERE Name = '%s' LIMIT 1;",mysql_real_escape_string($_GET['nosb']));
$result = mysql_query($SQL);
$num_rows = mysql_num_rows($result);
if($num_rows>0)
{
   $row = mysql_fetch_assoc($result);
   echo $rows['Contents'];
}else{
   echo "Not found";
}

//sidebar
if($rows['SidebarID'] >0 )
{
$SQL = sprintf("SELECT * FROM Contents WHERE Name = '%d' LIMIT 1;",$rows['SidebarID'])
$result = mysql_query($SQL);
$srow = mysql_fetch_assoc($result);
echo $srow['Contents'];
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.