Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Sep 2008
    Location
    Mexabet.biz
    Posts
    84
    Thanks
    12
    Thanked 0 Times in 0 Posts

    How can I make an included template to appear only on two pages

    I need help to make an included template to appear only on two pages and not on other web pages of a CMS. Can someone point me in the right direction, please on how to use the "elseif" statement to accomplish this?

    Right now tpl file appears on every page, which is not what I want.
    PHP Code:
    <?php
    //Display slide
    include('myfirst.tpl');
    ?>
    A hint of what I want to achieve is below:
    PHP Code:
    <php
    if "index.php"
    include('myfirst.tpl')
    elseif 
    "list-image.php"
    include('myfirst.tpl')
    else
    do 
    nothing
    ?>
     

  • #2
    met
    met is offline
    Regular Coder
    Join Date
    Oct 2009
    Location
    United Kingdom
    Posts
    728
    Thanks
    4
    Thanked 119 Times in 119 Posts
    first you need to determine the page.

    If you are using $_GET as a method of navigating (i.e. showing content based on the URL) then it would be easy enough to achieve.

    otherwise just put the include code on the pages you want, and don't put it on every other page.

  • #3
    New Coder
    Join Date
    Sep 2008
    Location
    Mexabet.biz
    Posts
    84
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Hi met,

    I want to put the "include" code only on index.php. If you know the correct elseif code for it, please help me.

    Quote Originally Posted by met View Post
    first you need to determine the page.

    If you are using $_GET as a method of navigating (i.e. showing content based on the URL) then it would be easy enough to achieve.

    otherwise just put the include code on the pages you want, and don't put it on every other page.

  • #4
    New Coder
    Join Date
    Sep 2008
    Location
    Mexabet.biz
    Posts
    84
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Sorry, I examine more closely and saw that the script uses $_GET['page'] method.

    The pages are "list-album", "list-image" and "image-detail". I want the template to be show up on "list-album" and "list-image", but not on "image-detail". Any help will be appreciated.

  • #5
    met
    met is offline
    Regular Coder
    Join Date
    Oct 2009
    Location
    United Kingdom
    Posts
    728
    Thanks
    4
    Thanked 119 Times in 119 Posts
    PHP Code:
    $page $_GET['page'];
    /* validate this */

    /* put this where you want myfirst.tpl to appear */
    if(!isset($page)) {
       
    /* this condition means no page is requested
       which implies you are on index.php */
    } else if($page == 'list-album' || $page == 'list-image') {
        include(
    'myfirst.tpl');  
    } else {
        
    /* this condition implies $page is set, but isn't list-album or list-image */

    Last edited by met; 10-16-2009 at 02:38 PM.

  • #6
    New Coder
    Join Date
    Sep 2008
    Location
    Mexabet.biz
    Posts
    84
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Hi met,

    Thanks for your help. However, I got error these messages after inserting your code:
    Code:
    Warning: Unterminated comment starting line 76 in /home3/myaccountname/public_html/myste/index.php on line 76
    
    Parse error: syntax error, unexpected $end in /home3/myaccountname/public_html/mysite/index.php on line 76

    Quote Originally Posted by met View Post
    PHP Code:
    $page $_GET['page'];
    /* validate this */

    /* put this where you want myfirst.tpl to appear */
    if(!isset($page)) {
       
    /* this condition means no page is requested
       which implies you are on index.php */
    } else if($page == 'list-album' || $page == 'list-image') {
        include(
    'myfirst.tpl');  
    } else {
        
    /* this condition implies $page is set, but isn't list-album or list-image


  • #7
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,849
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Quote Originally Posted by mexabet View Post
    I need help to make an included template to appear only on two pages and not on other web pages of a CMS. Can someone point me in the right direction, please on how to use the "elseif" statement to accomplish this?
    How do you distinguish them? Or which are those two pages?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #8
    met
    met is offline
    Regular Coder
    Join Date
    Oct 2009
    Location
    United Kingdom
    Posts
    728
    Thanks
    4
    Thanked 119 Times in 119 Posts
    Quote Originally Posted by mexabet View Post
    Hi met,

    Thanks for your help. However, I got error these messages after inserting your code:
    Code:
    Warning: Unterminated comment starting line 76 in /home3/myaccountname/public_html/myste/index.php on line 76
    
    Parse error: syntax error, unexpected $end in /home3/myaccountname/public_html/mysite/index.php on line 76

    missed the */ closing comment

  • Users who have thanked met for this post:

    mexabet (10-16-2009)

  • #9
    New Coder
    Join Date
    Sep 2008
    Location
    Mexabet.biz
    Posts
    84
    Thanks
    12
    Thanked 0 Times in 0 Posts
    abduraooft,

    The pages I want the template to show are "list-album" and "list-image", but not on "image-detail". However, the matter has been taken care of.

    met,

    Thanks for your efforts. The matter is solved.


  •  

    Posting Permissions

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