SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Mar 2012
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Can a Menu Item be a Conditional Link

    I have a site with basically 3 home pages depending on the type of customer. Depending on what home page they come in on, I want them to be linked back to that same home page when they clicked on "home" in the navigation or the logo.

    I'm guessing I need to use a Global variable along with some PHP. Any recommendations or possible Plugin?

    Thanks,
    Dan

  2. #2
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,337
    Mentioned
    192 Post(s)
    Tagged
    4 Thread(s)
    Welcome to Sitepoint Dan.

    This sounds like a perfect application for the PHP session variable.
    If you wish to 'persist' the choice (indicating which page the user "belongs to") you could write it into a cookie.
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  3. #3
    SitePoint Member
    Join Date
    Mar 2012
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your quick response ParkinT.
    I agree with the PHP session variable. Do you know if I can link to a specific webpage within the PHP code?

    ex: If session_variable = "homepage1"
    link to homepage1

    Thanks

  4. #4
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,337
    Mentioned
    192 Post(s)
    Tagged
    4 Thread(s)
    As PHP generates the HTML for the browser, you will make 'decisions' about which page; based on the user.
    Either the user details are retrieved from a database or dynamically (during this session) you have made a decision about this user as to which page(s) they will see.

    Build a global array of the "types" of users and related pages.
    Then when you create the hyperlink - in PHP code - just add the "href" value based on the current "UserType" (which I would include as a session variable). Something like this:
    Code:
    <a href="<?php echo $usertype[$current_user_type][0]; ?>" target="parent">HOME</a>
    This assumes you have the global array of user types (one element for each *different* user) and pages. For example:
    Code:
    <?php
    $usertype["basic"][0] = "home1.php";
    $usertype["basic"[1] = "links1.php";
    $usertype["advanced"][0] = "home2.php";
    $usertype["advanced"][1] = "links2.php";
    $usertype["novice"][0] = "home3.php";
    $usertype["novice"][1] = "links3.php";
    ?>
    I think you get the idea. Your actual variable names and page names will, likely, be different.

    =====================================================================
    Another - simple - approach would be to encode the pagenames IN the session (group) value. Like this:
    Code:
    <a href="home<?php echo session['user_group']; ?>.php">Home</a>
    You then create pages
    • homebasic.php
    • homeadvanced.php
    • homenovice.php


    Or some variation on this idea.
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  5. #5
    SitePoint Member
    Join Date
    Mar 2012
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks again.... I think that would work well.
    Since the "Home" link is a Wordpress Menu item, is it possible to add this code to it? (<a href="home<?php echo session['user_group']; ?>.php">Home</a>)

    Thanks for all your help.


Tags for this Thread

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
  •