开发者

One file, displaying code on one page, but excluding on another?

Can anyone advise how I'd alter a template which is called on every page load to display a particular section on just the one page?

I hope I explain this well enough...

index.php includes;

require_once('./cache/templates/sidebar.php');

Every subsequent page is built uses what's defined in this index.php file, meaning the sidebar.php is a must.

I'm wanting to edit s开发者_JAVA技巧idebar.php to contain an advert which displays solely on the index page.

At the moment, when I edit sidebar.php, so for instance, to display the letter "B", it will display on the homepage, and every other page like so;

Index Page: http://img.photobucket.com/albums/v684/nilsatis/1stack.jpg Every other page: http://img.photobucket.com/albums/v684/nilsatis/2stack.jpg

How can I dictate one area of an included file to display on one page but exclude showing on others?

Edit: Thanks very much for your time. It's really appreciated.

I inherited/purchased the website and I'm finding the index.php file very temperamental.

I'm attempting to put this code within the sidebar (or below it, above the footer) but any amend on index.php breaks it.

        }

        if (isset($url[1])) require_once('./cache/html/'.$url[0].'/'.$url[1].'.php');
        else require_once('./cache/html/'.$url[0].'.php');
    }
}
require_once('./cache/templates/sidebar.php');


}


require_once('./cache/templates/footer.php');


A quick and dirty hack would be inserting a custom CSS stylesheet on the index.php page that makes some div that's part of "sidebar.php" visible.

Example:

sidebar.php:

  <?php
    echo '<div id="theLetterB" style="display:none">B</div>';
  ?>

index.php:

  <?php
    if ($_SERVER['PHP_SELF'] == 'index.php') // Replace this with something to differentiate between pages
    {
      echo '<style type="text/css"> #theLetterB { display:block; } </style>';
    }
  ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜