Forum Moderators: coopster
details:
I have a standard sidebar of modules, which is being included in all pages via a simple 'php include ()' statement:
<?php // INCLUDE SIDEBAR.PHP?>
<?php include('includes/sidebar.php');?>
<?php // END SIDEBAR.PHP?>
This gets included on *all* pages.
Then I have a few unique pages - one is 'articles.php' - which require that same sidebar to be included, but with one additional module appended - which is itself a PHP include file called 'unique-module.php'.
This extra module is *only* to be included in the sidebar on these few unique pages. Additionally, this extra module needs to be placed in the middle of the overall sidebar.php file, so I can't just call it in as a separate include in the base pages. (if that makes sense).
I also can't use a simple CSS solution to hide it or show it (i.e., with 'display' definitions based on whether particular selector combinations are present on the calling page) because that will still leave the unique content showing when styles are turned off.
I need a truly dynamic control here, and I think a php "if" statement will do the trick, I just can't figure it out on my own.
I am thinking I can do this using the unique page ID attributes I've put on each pages' 'body' tag. For example, for the unique "articles.php" page, the 'body' tag has an ID:
<body id="articles">
So I am guessing I should be able to use a php "if" / include statement in the actual 'sidebar.php' include file itself that basically says "if body ID = 'articles', then include 'unique-module.php'. This way, when the 'sidebar.php' include file gets called by the base page, it can be passed that ID and be instructed to include its interior 'unique-module.php' include file.
In layman's terms, that's the goal. Make sense? I'm sure it's easy enough, but I haven't found it yet.
Thanks for any help!
In the file which is parsed first and which is unique to that page, you set a PHP variable:
<?php
$include_in_sidebar="uniquemodule.php";
?>
Then, later, in your sidebar file, at the correct place:
<?php
if ($include_in_sidebar) include($include_in_sidebar);
?>