Results 1 to 3 of 3

Thread: php if/else or switch by PageID

  1. #1
    Join Date
    Jun 2006
    Posts
    2

    Default php if/else or switch by PageID

    The template I'm creating has different graphical headers for each page, as well as a sub-menu that changes depending on the area of the website. So far, the only way I can find to do this in Open Realty is to create a page template for every page in the website - which is redundant, and, I hope, unnecessary.

    The way I would do this with other CMS's is to use a php if/else or switch statement that displays/hides elements based on the page or type of page being displayed. There is a variable $page_id and a resultant PageID that I believe I should be able to use to do this, but so far, all my efforts to use these in php statements have failed. I tried to include the code in an addon instead, but I had no better luck that way.

    So far, it seems that this is just not possible with OR, perhaps due to the order in which pages/addons etc are parsed - but I really hope I'm wrong. Is there any way to use either $page_id or PageID in php code in the template?

    Even if I do have to put the code in an addon, that would be greatly preferable to creating a new template for each page. I'm up to 20 pages and 20 templates so far, and I'm not even half through the client site.

    Any help at all is greatly appreciated.

  2. #2
    Join Date
    Jun 2005
    Posts
    72

    Default Re: php if/else or switch by PageID

    in the template files you should be able to access URL GET variables. The PageID is a GET variable. So the following works.

    PHP Code:
    <?php
    if ($_GET['action'] == 'page_display'){
        if (
    $_GET['PageID'] == 1
        { 
          echo 
    '<h3> Stuff for pageid 1</h3>';
        }
    }
    ?>
    or

    PHP Code:
    <?php
    if ($_GET['action'] == 'page_display'){
        if (
    $_GET['PageID'] == 1
        { 
            
    ?>
          <h3> Stuff for pageid 1 </h3>
            <?php
        
    }
    }
    ?>
    Home page doesn't have these get variables, so the template should show by default what you want on index.php.

    Just an idea. There are other ways to do it, but this method can keep everything in one template file.

  3. #3
    Join Date
    Jun 2006
    Posts
    2

    Talking Re: php if/else or switch by PageID

    Thank you! Thank you! Thank you!

    I have just tested it, and it works perfectly. Even with the Search Engine Friendly urls enabled, which I was a bit worried about.

    A thousand thousand thanks to you, as I was just about to pitch the computer and everything on it out of the window...

Bookmarks

Posting Permissions

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