www.webdeveloper.com
Results 1 to 12 of 12

Thread: Hide div from all pages but front page

  1. #1
    Join Date
    Feb 2009
    Posts
    12

    Lightbulb Hide div from all pages but front page

    Hi guys,

    I have website with about 10 pages, and they are interconnected so if I add div tag to my front page it will show on all the pages. What I need is to add div tag to my front page and be seen only on the front page.

    I was looking on internet for solution for last two days, and only think I found is to control div tags by cookies but the solution i found only allow the div tag be seen only once in 24 hours. And I need the div tag to be seen every time someone gos to my front page.

    I am not sure if this is possible, and I know nothing about working with cookies.

    If someone can please help me out here it will be mostly appreciated.

    Rich

  2. #2
    Something like this might help:
    PHP Code:
    if (pagename){
    "<div id='blah'></div>";
    }else{
    "<div id='blah' style='display:none;'></div>";


  3. #3
    Join Date
    Jul 2008
    Location
    Charlottesville, VA
    Posts
    91
    Coyotelab has a solution for you there. That will hide the <div>. If, however, you don't want that <div> output at all, something even simpler will work:

    Code:
    if ($pagename=='home'){
    echo "<div id='blah'>my blah content</div>";
    }
    It's up to you to determine what page you're loading. There are various ways to do that, like looking at $_SERVER['PHP_SELF'].

    Frank

  4. #4
    Join Date
    Feb 2009
    Posts
    12
    Thanks guys for fast replay

    Code:
    <?php if ($pagename='$home'){
    echo "<div id='blah'></div>";
    } ?>
    If I use the code above it dos not show the div at all

    Code:
    <?php if ($pagename='$home'){
    "<div id='blah'></div>";
    }else{
    "<div id='blah' style='display:none;'></div>";
    } ?>
    If I use this above it shows the div on all pages.

    Maybe this will help this code below is the main setting for all website:
    Code:
    <?php echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n"; ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" dir="<?php echo $direction; ?>" lang="<?php echo $language; ?>" xml:lang="<?php echo $language; ?>">
    <head>
    <link rel="favicon" href="favicon.ico" type="image/icon" />
    <link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
    <title><?php echo $title; ?></title>
    <?php if ($description) { ?>
    <meta name="description" content="<?php echo $description; ?>" />
    <?php } ?>
    <base href="<?php echo $base; ?>" />
    <link rel="stylesheet" type="text/css" href="catalog/view/theme/Rich_Store_v.1.3/stylesheet/stylesheet.css" />
    <!--[if lt IE 7]>
    <link rel="stylesheet" type="text/css" href="catalog/view/theme/Rich_Store_v.1.3/stylesheet/ie6.css" />
    <![endif]-->
    <script type="text/javascript" src="catalog/view/javascript/jquery/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="catalog/view/javascript/jquery/thickbox/thickbox-compressed.js"></script>
    <link rel="stylesheet" type="text/css" href="catalog/view/javascript/jquery/thickbox/thickbox.css" />
    <script type="text/javascript" src="catalog/view/javascript/jquery/tab.js"></script>
    </head>
    <body>
    <div id="container">
      <div id="header"><?php echo $header; ?></div>
      <div id="breadcrumb">
        <?php foreach ($breadcrumbs as $breadcrumb) { ?>
        <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
        <?php } ?>
      </div>
      <div id="column_left">
        <?php foreach ($modules as $module) { ?>
        <?php if ($module['position'] == 'left') { ?>
        <?php echo ${$module['code']}; ?>
        <?php } ?>
        <?php } ?>
      </div>
      <div id="column_right">
        <?php foreach ($modules as $module) { ?>
        <?php if ($module['position'] == 'right') { ?>
        <?php echo ${$module['code']}; ?>
        <?php } ?>
        <?php } ?>
      </div>
      <div id="content"><?php echo $content; ?></div>
      <div id="footer"><?php echo $footer; ?></div>
    </div>
    </body>
    </html>
    I try different varieties and no luck so far. If you have any idea please let me know.

  5. #5
    Join Date
    May 2007
    Posts
    81
    You need to grab the page name from the server as mentioned by FrankTheTank and assign it to the $pagename variable. One way to do that would be as follows:

    <?php $pagename=substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
    ?>

    Joe

  6. #6
    Join Date
    Aug 2006
    Posts
    1,904
    One wonders what answers you would have had if you'd have posted this in the CSS forum. Perhaps something like:

    CSS:
    Code:
    #fpdiv {display:none}
    #indexpage fpdiv {display:inline}
    index.html
    Code:
    <body id="indexpage">
    <div id="fpdiv"></div>
    ...
    </body>
    Other HTML pages:
    Code:
    <body>
    <div id="fpdiv"></div>
    ...
    </body>

  7. #7
    Join Date
    Feb 2009
    Posts
    12
    Quote Originally Posted by tracknut View Post
    One wonders what answers you would have had if you'd have posted this in the CSS forum. Perhaps something like:

    CSS:
    Code:
    #fpdiv {display:none}
    #indexpage fpdiv {display:inline}
    index.html
    Code:
    <body id="indexpage">
    <div id="fpdiv"></div>
    ...
    </body>
    Other HTML pages:
    Code:
    <body>
    <div id="fpdiv"></div>
    ...
    </body>
    Thanks for helping, the trouble I have is I don't have other html pages.
    This is template system I am working on, i have only one <body> tag, the rest of pages are pull out of one layout.tpl.

    If you have any other idea with HTML or CSS let me please know.

    PS: I am steal working on how to pull the home page from database I am not that good with php.

  8. #8
    Join Date
    Aug 2006
    Posts
    1,904
    But that big glob of php you've shown above, that's the thing that's displaying all your pages, right? What's one more if-statement, to stick "id=indexpage" in the body tag?

    Dave

  9. #9
    Join Date
    Feb 2009
    Posts
    12
    Quote Originally Posted by tracknut View Post
    But that big glob of php you've shown above, that's the thing that's displaying all your pages, right?
    Yes this is the template whats controlling all the pages, this is the main look, than there are sub .tpl files and they are defying the details but they do not have <body> tags.

    What's one more if-statement, to stick "id=indexpage" in the body tag?

    Dave
    I am not sure what you asking me here but if I do what you suggesting the div I need to show only on front page dos not showing up at all.

  10. #10
    Join Date
    Aug 2006
    Posts
    1,904
    Quote Originally Posted by richard12345 View Post
    I am not sure what you asking me here but if I do what you suggesting the div I need to show only on front page dos not showing up at all.
    You've already tested it out? Can you give a link to the live site?

    Dave

  11. #11
    Join Date
    Feb 2009
    Posts
    12
    Sorry i don't have it on site I am testing this on my private server.

  12. #12
    Join Date
    Apr 2007
    Posts
    1,664
    Variables inside single quotes are not parsed as variables but literal text (including the dollar sign). Here are some examples of how to use the suggested logic. (double equals as well)

    PHP Code:
    <?php 
    $home
    ='index.php'
    if ($pagename==$home){
        echo 
    "<div id='blah'></div>";

    ?>
    PHP Code:
    <?php 
    if ($pagename=='index.php'){
        echo 
    "<div id='blah'></div>";

    ?>
    or I would probably use this

    PHP Code:
    <?php 
    if ($_SERVER['SCRIPT_NAME']=='/path/to/index.php'){
        echo 
    "<div id='blah'></div>";

    ?>
    echo $_SERVER['SCRIPT_NAME'] on the index page to get the actual value you need to add to the if statement.
    Last edited by SyCo; 08-11-2009 at 06:14 PM.
    Anti Linux rants are usually the result of a lack of Linux experience, while anti Windows rants are usually a result of a lot of Windows experience.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles