473,395 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Underline the Current Page's Title in menu

Hey all!

I'm building a site for a friend which uses this Wordpress theme:

http://www.felixkrusch.de/about

^ As you can see by visting the site, the title of the current page is always underlined on the main menu.

In the code the menu is displayed by this code:

Expand|Select|Wrap|Line Numbers
  1. <li <?php if(is_home()){echo 'class="current_page_item"';}?>><a href="<?php bloginfo('siteurl'); ?>" title="Home">Home</a></li>
  2.  
  3. <?php wp_list_pages('title_li=&depth=1');?>
and a snippet of css in the stylesheet:

Expand|Select|Wrap|Line Numbers
  1. .current_page_item a {
  2.  
  3. color:#000;
  4.  
  5. text-decoration: underline;
  6.  
  7. }
I want to add links to category pages in the menu, but if I add an example like this to the menu:

Expand|Select|Wrap|Line Numbers
  1. <a href="blahblah.com/cat/videos">Videos</a>
There is no underline for that page.

Does anyone know a way that I can achieve the same underline effect for non-Pages I add to the menu?

There must be some way to adapt this code for other URLs?

Expand|Select|Wrap|Line Numbers
  1. <li <?php if(is_home()){echo 'class="current_page_item"';}?>><a href="<?php bloginfo('siteurl'); ?>" title="Home">Home</a></li>
If anyone can help I'd be hugely grateful, thank you in advance!
Sep 4 '08 #1
11 5619
Dormilich
8,658 Expert Mod 8TB
put your link in an element (li, div, span, ...) that contains the current_page_item class.
Expand|Select|Wrap|Line Numbers
  1. <span class="current_page_item">
  2.   <a href="_your_uri_">_link_text_</a>
  3. </span>
regards
Sep 4 '08 #2
I might be wrong but I don't think that would work.

I want the underline to appear only on the page currently being browsed by the visitor. If I added the above bit of code, would it not always apply the underline?

Thanks,
Sep 4 '08 #3
David Laakso
397 Expert 256MB

There must be some way to adapt this code for other URLs?

Expand|Select|Wrap|Line Numbers
  1. <li <?php if(is_home()){echo 'class="current_page_item"';}?>><a href="<?php bloginfo('siteurl'); ?>" title="Home">Home</a></li>
Try the PHP forum PHP forum
Sep 4 '08 #4
Thanks for the help all,

I will move this conversation to the PHP forum, cheers.
Sep 8 '08 #5
eWish
971 Expert 512MB
Moving to PHP Forum.

--Kevin
Sep 8 '08 #6
Dormilich
8,658 Expert Mod 8TB
There must be some way to adapt this code for other URLs?
Expand|Select|Wrap|Line Numbers
  1. <li <?php if(is_home()){echo 'class="current_page_item"';}?>>
  2.     <a href="<?php bloginfo('siteurl'); ?>" title="Home">Home</a>
  3. </li>
do you know, how the is_home() function works? then you could it adapt for categories too.
Sep 9 '08 #7
do you know, how the is_home() function works? then you could it adapt for categories too.
Dormilich: I have no idea how the is_home() function works.

Do you have any idea?

Repeating it for categories would be perfect.

Thanks
Sep 10 '08 #8
Dormilich
8,658 Expert Mod 8TB
option 1 - you have access to the server and the function is defined somewhere in a script file on the server - just scan the script files for this function

option 2 - is_home() belongs to a wordpress hosted script - no luck

option 3 - there is a wordpress documentation

option 4 - write your own is_category() function

for option 4 I'd like to see more of the script, because this function also depends on how the category menu is build. as a general idea the function would probably compare the siteurl with the category link (e.g. preg_match()).

regards
Sep 11 '08 #9
I think option 3:

http://codex.wordpress.org/Condition..._Category_Page

I am wholly uneducated in PHP so I hope you can confirm or deny my theory, that I should be able to get the result I want using the structure below.

Expand|Select|Wrap|Line Numbers
  1.       <li <?php if(is_home()){echo 'class="current_page_item"';}?>>
  2.           <a href="http://homepage.com" title="Home">Home</a>
  3.       </li>
  4.  
  5.     <li <?php if(is_category('9')){echo 'class="current_page_item"';}?>>
  6.           <a href="http://homepage.com/cat/apple" title="Posts Filed in Apple">Apple</a>
  7.  
  8.     <li <?php if(is_category('10')){echo 'class="current_page_item"';}?>>
  9.           <a href="http://homepage.com/cat/windows" title="Posts Filed in Windows">Windows</a>
  10.  
For the record: categories are each given a numeric value besides its name, Apple might be 9, Windows might be 10, and so on, like I've shown here.
Sep 11 '08 #10
Dormilich
8,658 Expert Mod 8TB
That's exactly how I would do that. despite is_category() fires only if the page displayed is the category's top page, maybe you want to go for in_category() (marking all pages that belong to that category)

regards
Sep 11 '08 #11
Thanks for the great advice, I truly appreciate your help!

Will repost here to let you know how I get on.

Best,
Sep 12 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Tim Daneliuk | last post by:
I am currently underling the first character of a menu title (to indicate its shortcut/accelerator key) like this: self.WildBtn = Menubutton(self.mBar, text=WILDMENU, underline=0, state=DISABLED)...
1
by: bayouprophet | last post by:
Cant get menu script to to put linked page in the same frame. I am new to Java and I am wondering what am I doing wrong? below are my java applet file, frame.html file, and my text file and one...
8
by: Dan | last post by:
When a user clicks on a link in my menu, I want the background color of the link that comes up in the hover to remain on the destination page. My menu looks like this: <div id="adminmenu"> <a...
16
by: michael | last post by:
Is it possible to get all href URLs contained in a unordered list and place them in an array? Or in fact two different arrays, differently named one for each <ul> group? <ul> <li><a...
29
by: jmaxsherkimer | last post by:
the site we're working on has some anchor links, you click them they scroll to the bottom of the page with the answers to the questions linked on to. is there anyway to make it so that the links...
0
by: MS Development | last post by:
Hello Newgroup, I'm new to ASP.NET and its nice navigation features. I have now some problems with them which I hope can anyone solve. So here we go: The generel idea is I have a page like e....
7
by: imtmub | last post by:
I have a page, Head tag Contains many Scripts and style sheet for Menu and Page. This code working fine and displaying menus and page as i wanted. Check this page for reference....
3
by: Mark B | last post by:
I want to create a top navigation bar: Home Products Services About Contact I have been trying to use web.sitemap as the source for a menu control as show in the...
8
by: Mateusz Viste | last post by:
Hi, I'm not sure if my question is really related to JavaScript, so please excuse me if that's not the case (and maybe you guys would have an idea what's the cause is and where could I ask)... ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.