Support Forums

Need help with an if/else statement on links.

This is a discussion on Need help with an if/else statement on links. within the Templates, HTML, CSS, and Design Help forums, part of the General category; In my layout.tpl.php file I'm using the fllowing code to produce my menu; Code: <!-- start menu --> <div id="menu"> ...


Go Back   68 Classifieds Forums > General > Templates, HTML, CSS, and Design Help

Reply
 
Thread Tools Display Modes
Old 09-20-2007, 02:19 AM   #1
Just get on with it!
 
michael's Avatar
 
Join Date: Jan 2007
Location: Milton Keynes, England
Posts: 474
Rep Power: 31
michael is just really nice michael is just really nice
Default Need help with an if/else statement on links.

In my layout.tpl.php file I'm using the fllowing code to produce my menu;
Code:
 
<!-- start menu -->
<div id="menu">
 <ul>
  <li class="current_page_item"><a href="http://www.mkclassifieds.co.uk/index.php">Homepage</a></li>
  <li><a href="#">register</a></li>
  <li><a href="#">contact</a></li>
  <li><a href="#">sell</a></li>
  <li><a href="#">buy</a></li>
 </ul>
</div>
<!-- end menu -->
As you can see, class="current_page_item" produces the 'highlighted tab' which denotes the page you are on.

Can any of you smart people produce an if/else statement I can use on each link that would use class="current_page_item" when that link is clicked? See www.mkclassifieds.co.uk

Many thanks
__________________
M Michael
V4.2.1 Developer - Sigma Template


"All truths are easy to understand once they are discovered; the point is to discover them" - Galileo Galilei (1564 - 1642)
michael is offline   Reply With Quote
Old 09-20-2007, 06:39 AM   #2
Just get on with it!
 
michael's Avatar
 
Join Date: Jan 2007
Location: Milton Keynes, England
Posts: 474
Rep Power: 31
michael is just really nice michael is just really nice
Default

I think all I need is the correct IF statement. Because layout.tpl.php is a static page index.php will always be the current_page_item. I guess I need the IF statement to simply say that IF a link is clicked treat it as the current_page_item.

For example, the 'register' link might look something like the following;

Code:
 
  <?php if what do I put here ?>
   <li class="current_page_item">
    <a href="http://www.mkclassifieds.co.uk/userjoin.php" ?>" title="Register Now">Register</a>
   </li>
 <?php } else { ?>
  <li>
   <a href="http://www.mkclassifieds.co.uk/userjoin.php" ?>" title="Register Now">Register</a>
  </li>
 <?php } ?>
What do you think?
__________________
M Michael
V4.2.1 Developer - Sigma Template


"All truths are easy to understand once they are discovered; the point is to discover them" - Galileo Galilei (1564 - 1642)
michael is offline   Reply With Quote
Old 09-20-2007, 09:40 AM   #3
68 Classifieds Staff
 
Eric Barnes's Avatar
 
Join Date: Mar 2006
Location: Belmont, NC
Posts: 5,489
Rep Power: 133
Eric Barnes is just really nice Eric Barnes is just really nice
Default

I have just done this on a site and here is what I did:

Code:
<ul>
            <li{if $body=='home.tpl.php'} class="current_page_item"{/if}><a href="#">Homepage</a></li>
            {if $smarty.session.username<>'' || $smarty.cookies.username<>""}
            <li{if $body=='user/userindex.tpl.php'} class="current_page_item"{/if}><a href="{$smarty.const.URL}/userindex.php">My Account</a></li>
            {else}
            <li{if $body == "user/userlogin.tpl.php"} class="current_page_item"{/if}><a href="login.php">Login</a></li>
            {/if}
            <li{if $checkout_nav == "Y"} class="current_page_item"{/if}><a href="usercheckout.php">Add a Listing</a></li>
            <li{if $smarty.get.page==6} class="current_page_item"{/if}><a href="{$smarty.const.URL}/pages.php?page=6">Advertising</a></li>
            <li><a href="#">About</a></li>
            {if $smarty.session.username<>'' || $smarty.cookies.username<>""}
            <li><a href="{$smarty.const.URL}/logout.php">Logout</a></li>
            {else}
            <li{if $body == "user/userjoin.tpl.php"} class="current_page_item"{/if}><a href="{$smarty.const.URL}/userjoin.php">Account Signup</a></li>
            {/if}
        </ul>
One thing you can do is use the debug window to find the body variable and use it which is what I did.
__________________
Eric Barnes
68 Classifieds Developer
Customer Area | Issue Tracker | Documentation | 68C Mods | 68 @ Twitter | My Modules
Eric Barnes is offline   Reply With Quote
Old 09-20-2007, 09:41 AM   #4
68 Classifieds Staff
 
Eric Barnes's Avatar
 
Join Date: Mar 2006
Location: Belmont, NC
Posts: 5,489
Rep Power: 133
Eric Barnes is just really nice Eric Barnes is just really nice
Default

PS: I was using that same exact template you are.
__________________
Eric Barnes
68 Classifieds Developer
Customer Area | Issue Tracker | Documentation | 68C Mods | 68 @ Twitter | My Modules
Eric Barnes is offline   Reply With Quote
Old 09-20-2007, 10:10 AM   #5
Just get on with it!
 
michael's Avatar
 
Join Date: Jan 2007
Location: Milton Keynes, England
Posts: 474
Rep Power: 31
michael is just really nice michael is just really nice
Default

Very cool! Thanks Eric, your code will help me with other templates too.

As you are familiar with this template - extended right - could you help me to close off the Members Menu more neatly?

I've designed it only to appear when a member is logged in so use demo for both username and password.

Many thanks (and I should buy you a beer or three sometime)

Michael
__________________
M Michael
V4.2.1 Developer - Sigma Template


"All truths are easy to understand once they are discovered; the point is to discover them" - Galileo Galilei (1564 - 1642)
michael is offline   Reply With Quote
Old 09-20-2007, 10:23 AM   #6
68 Classifieds Staff
 
Eric Barnes's Avatar
 
Join Date: Mar 2006
Location: Belmont, NC
Posts: 5,489
Rep Power: 133
Eric Barnes is just really nice Eric Barnes is just really nice
Default

Michael,

For the nav you need to keep everything in the same div.

For example:
Code:
<div id="sidebar">
<ul>
<li>
<h2>Members Menu</h2>
<ul><li>Member Links</li></ul>
</li> 
<li>
<h2>Categories</h2>
<ul><li>Category Links</li></ul>
</li>
</ul>
</div>
I will pm you a link to the site I was working on.
__________________
Eric Barnes
68 Classifieds Developer
Customer Area | Issue Tracker | Documentation | 68C Mods | 68 @ Twitter | My Modules
Eric Barnes is offline   Reply With Quote
Old 09-20-2007, 11:16 AM   #7
Just get on with it!
 
michael's Avatar
 
Join Date: Jan 2007
Location: Milton Keynes, England
Posts: 474
Rep Power: 31
michael is just really nice michael is just really nice
Default

Eric, your code works beautifully in IE7 but has wrecked the layout in Firefox (index page only). Any ideas?
__________________
M Michael
V4.2.1 Developer - Sigma Template


"All truths are easy to understand once they are discovered; the point is to discover them" - Galileo Galilei (1564 - 1642)

Last edited by michael; 09-20-2007 at 11:20 AM.
michael is offline   Reply With Quote
Old 09-20-2007, 11:21 AM   #8
68 Classifieds Staff
 
Eric Barnes's Avatar
 
Join Date: Mar 2006
Location: Belmont, NC
Posts: 5,489
Rep Power: 133
Eric Barnes is just really nice Eric Barnes is just really nice
Default

Change the side bar section to this:

Code:
<!-- start sidebar -->
    <div id="sidebar">
        <ul>
{if $smarty.session.username<>'' || $smarty.cookies.username<>""}
            <li>
                <h2>Members Menu</h2>
                <ul>
        <li><a href="http://www.mkclassifieds.co.uk/userindex.php">My Account</a></li>
        <li><a href="http://www.mkclassifieds.co.uk/userfavorites.php">My Favourites</a></li>
        <li><a href="http://www.mkclassifieds.co.uk/usercheckout.php">Place An Ad'</a></li>
        <li><a href="http://www.mkclassifieds.co.uk/userbrowselistings.php">Modify An Ad'</a></li>
        <li><a href="http://www.mkclassifieds.co.uk/usermemberships.php">Purchase a Membership</a></li>
        <li><a href="http://www.mkclassifieds.co.uk/logout.php">Logout</a></li>
                </ul>
            </li>
                {/if}
            <li>
                <h2>Categories</h2>
            <ul>
    <li><a href="http://www.mkclassifieds.co.uk/category.php?cat=home-garden">Home & Garden</a></li>
    <li><a href="http://www.mkclassifieds.co.uk/category.php?cat=motoring">Motoring</a></li>
    <li><a href="http://www.mkclassifieds.co.uk/category.php?cat=property">Property</a></li>
    <li><a href="http://www.mkclassifieds.co.uk/category.php?cat=recruitment_1">Recruitment</a></li>
    <li><a href="http://www.mkclassifieds.co.uk/category.php?cat=services_1">Services</a></li>
    <li><a href="http://www.mkclassifieds.co.uk/category.php?cat=computing">Computing</a></li>
    <li><a href="http://www.mkclassifieds.co.uk/category.php?cat=travel">Travel</a></li>
    <li><a href="http://www.mkclassifieds.co.uk/category.php?cat=electrical">Electrical</a></li>
    <li><a href="http://www.mkclassifieds.co.uk/category.php?cat=leisure">Leisure</a></li>
    <li><a href="http://www.mkclassifieds.co.uk/category.php?cat=music">Music</a></li>
    <li><a href="http://www.mkclassifieds.co.uk/category.php?cat=pets">Pets</a></li>
    <li><a href="http://www.mkclassifieds.co.uk/category.php?cat=health-fitness">Health & Fitness</a></li>
    <li><a href="http://www.mkclassifieds.co.uk/category.php?cat=whats-on-in-mk">What's on in MK</a></li>
    <li><a href="http://www.mkclassifieds.co.uk/category.php?cat=odds-sods">Odds & Sods</a></li>
    <li><a href="http://www.mkclassifieds.co.uk/category.php?cat=adult_1">Adult</a></li>
                </ul>
            </li>
        </ul>
    </div>
    <!-- end sidebar -->
__________________
Eric Barnes
68 Classifieds Developer
Customer Area | Issue Tracker | Documentation | 68C Mods | 68 @ Twitter | My Modules
Eric Barnes is offline   Reply With Quote
Old 09-20-2007, 11:32 AM   #9
Just get on with it!
 
michael's Avatar
 
Join Date: Jan 2007
Location: Milton Keynes, England
Posts: 474
Rep Power: 31
michael is just really nice michael is just really nice
Default

You're a goddam hero!

__________________
M Michael
V4.2.1 Developer - Sigma Template


"All truths are easy to understand once they are discovered; the point is to discover them" - Galileo Galilei (1564 - 1642)
michael is offline   Reply With Quote
Old 09-20-2007, 12:01 PM   #10
68 Classifieds Staff
 
Eric Barnes's Avatar
 
Join Date: Mar 2006
Location: Belmont, NC
Posts: 5,489
Rep Power: 133
Eric Barnes is just really nice Eric Barnes is just really nice
Default

I wouldn't say that. I just have special ninja powers.
__________________
Eric Barnes
68 Classifieds Developer
Customer Area | Issue Tracker | Documentation | 68C Mods | 68 @ Twitter | My Modules
Eric Barnes is offline   Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why does google show no links to my site? bgordon Site Marketing 4 11-07-2006 02:09 PM
Google Juice fjarabeck Site Marketing 0 04-27-2006 01:40 PM


All times are GMT -4. The time now is 11:27 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2011, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0