#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    9
    Rep Power
    0

    Post How do I create active links?


    Hi

    I have set up a Wordpress website and would like the main navigation links to remain active for each page (ie. remain blue once the user is on the current page).

    Thing is I have used a custom menu, therefore the 'current-page-item' within the theme I have used is ignoring the custom CSS.

    Is there some coding I need to insert into the header.php where the links are ?

    please help
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,850
    Rep Power
    6351
    set a new style for current-page-item that makes them blue.

    Also: why would you want to break a fundamental part of the web? When I click a blue link, I expect a new page, not THIS PAGE I'M ON. You're only going to anger your users by breaking standard conventions.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    9
    Rep Power
    0

    Wordpress - How do I create active links?


    Hi,

    this style is already assigned in the css file, but the wordpress backend coding isn't assigning the active links because the nav links have been manually inserted into the header.php.

    go to (eureka-marketing.co.uk/drive) to see website

    I just want to know if I need to include some code in the header.php ?
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    9
    Rep Power
    0
    Originally Posted by ManiacDan
    set a new style for current-page-item that makes them blue.

    Also: why would you want to break a fundamental part of the web? When I click a blue link, I expect a new page, not THIS PAGE I'M ON. You're only going to anger your users by breaking standard conventions.
    Hi,

    this style is already assigned in the css file, but the wordpress backend coding isn't assigning the active links because the nav links have been manually inserted into the header.php.

    go to (eureka-marketing.co.uk/drive) to see website

    I just want to know if I need to include some code in the header.php ?
  8. #5
  9. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,850
    Rep Power
    6351
    Well then...yes. You need to change header.php to dynamically change the link classes to the right type. There must be a function in wordpress that returns the current page.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    9
    Rep Power
    0
    Originally Posted by ManiacDan
    Well then...yes. You need to change header.php to dynamically change the link classes to the right type. There must be a function in wordpress that returns the current page.
    Do you have any examples or guides you can show me please?

    that would help alot
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    9
    Rep Power
    0
    if it helps, this is the navigation code inserted into the header.php :

    <div class="left_menu main-nav"><div class="menu-left-menu-container">

    <ul id="menu-left-menu" class="menu">

    <li id="menu-item-371"><a href="/drive/our-work">Our work</a></li>

    <li id="menu-item-371"><a href="/drive/our-people-2">Our people</a></li>

    <li id="menu-item-248"><a href="/drive/what-we-do">What we do</a></li>

    </ul></div></div>

    <div class="right_menu main-nav"><div class="menu-right-menu-container"><ul id="menu-right-menu" class="menu">

    <li id="menu-item-252" class="menu-item"><a href="/drive/gallery">Gallery</a></li>

    <li id="menu-item-256" class="menu-item"><a href="/drive/news">News</a></li>

    <li id="menu-item-379" class="menu-item-379"><a href="/drive/contact">Contact us</a></li>

    </ul></div></div>
  14. #8
  15. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,850
    Rep Power
    6351
    There [probably] exists a wordpress function which will return the current page. Find that function (using google or by looking at similar code where this happens), then see what it returns for each of these pages. When you find that out, your code is going to be something like:
    PHP Code:
    <li id="menu-item-371"><a href="/drive/our-work" <?php if ( theFunctionYouFound() == 'THE_VALUE_FOR_OUR_WORK' ) { echo " class='current_page_item'"; }?>>Our work</a></li>
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    9
    Rep Power
    0
    Originally Posted by ManiacDan
    There [probably] exists a wordpress function which will return the current page. Find that function (using google or by looking at similar code where this happens), then see what it returns for each of these pages. When you find that out, your code is going to be something like:
    PHP Code:
    <li id="menu-item-371"><a href="/drive/our-work" <?php if ( theFunctionYouFound() == 'THE_VALUE_FOR_OUR_WORK' ) { echo " class='current_page_item'"; }?>>Our work</a></li>
    I tried inserting this, but it didnt work

    <li id="menu-item-371"><a href="/drive/our-work" <?php if (is_page('our-work')) == 'our-work' ) { echo "class='current_page_item'"; }?>>Our work</a></li>
  18. #10
  19. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,850
    Rep Power
    6351
    This is invalid. It contains too many right parens (three) for the left parens (two): if (is_page('our-work')) == 'our-work' )

    If is_page('our-work') returns TRUE or FALSE (as in, it returns true when the current page is named 'our-work', then the correct code would be:

    PHP Code:
    <li id="menu-item-371"><a href="/drive/our-work" <?php if(is_page('our-work')) { echo " class='current_page_item'"; }?>>Our work</a></li>
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    9
    Rep Power
    0
    no worries, I think I've sorted it:

    <li <?php $string = basename($_SERVER['REQUEST_URI']); if ( strpos($string, 'our-work') !== false ){ echo "class='current-menu-item'"; } ?> ><a href="/drive/our-work">Our work</a></li>

    thanks for your help ManiacDan
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    9
    Rep Power
    0
    sorry, one last thing, is there a way of adding an Array of pages to be Active in this code?
    <li <?php $string = basename($_SERVER['REQUEST_URI']); if ( strpos($string, 'our-work') !== false ){ echo "class='current-menu-item'"; } ?> ><a href="/drive/our-work">Our work</a></li>
  24. #13
  25. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,850
    Rep Power
    6351
    There might be, but that depends on your logic. Which pages do you want to be "active" when the current page is the 'our work' page? When you figure that out, add an OR or an [PHPNET="in_array"]in_array[/PHPNET] call to the IF condition of those pages.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2014
    Posts
    9
    Rep Power
    0
    there are 8 pages within the 'our-work' page, for example one page is: eureka-marketing.co.uk/drive/caterham

    this and the other 7 need to have the 'our work' menu active blue
  28. #15
  29. Wiser? Not exactly.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    5,934
    Rep Power
    4033
    You could either list all the pages in an array and check for them, or re-work your URL structure so that the 'our-work' portion is in each of those URLs. For example use /drive/our-work/caterham/ rather than /drive/caterham/. I'm not that familiar with wordpress so I'm not sure how or if it's possible to make such a URL change.

    As for the array option, $_SERVER['REQUEST_URI'] should return the whole path so you could just list them out and check with in_array, eg:
    Code:
    if (in_array($_SERVER['REQUEST_URI'], array('/drive/our-work/', '/drive/caterham/', ...))){ echo "class='current-menu-item'"; }
    On a side note, you should remove that anti-right-click stuff, unless you want to annoy/drive away your users for no reason.
    Recycle your old CD's, don't just trash them



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud

IMN logo majestic logo threadwatch logo seochat tools logo