Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old September 4th, 2008, 01:33 PM
Newbie
 
Join Date: Sep 2008
Posts: 8
Default 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:

Code:
<li <?php if(is_home()){echo 'class="current_page_item"';}?>><a href="<?php bloginfo('siteurl'); ?>" title="Home">Home</a></li>

<?php wp_list_pages('title_li=&depth=1');?>
and a snippet of css in the stylesheet:

Code:
.current_page_item a {

color:#000;

text-decoration: underline;

}
I want to add links to category pages in the menu, but if I add an example like this to the menu:

Code:
<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?

Code:
<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!
Reply
  #2  
Old September 4th, 2008, 02:28 PM
Dormilich's Avatar
Expert
 
Join Date: Aug 2008
Location: Leipzig, Germany
Age: 31
Posts: 599
Default

put your link in an element (li, div, span, ...) that contains the current_page_item class.
Code:
<span class="current_page_item">
  <a href="_your_uri_">_link_text_</a>
</span>
regards
Reply
  #3  
Old September 4th, 2008, 03:12 PM
Newbie
 
Join Date: Sep 2008
Posts: 8
Default

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,
Reply
  #4  
Old September 4th, 2008, 03:35 PM
David Laakso's Avatar
Expert
 
Join Date: Aug 2008
Location: US
Posts: 302
Default

Quote:
Originally Posted by dominoeffect

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

Code:
<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
Reply
  #5  
Old September 8th, 2008, 10:10 AM
Newbie
 
Join Date: Sep 2008
Posts: 8
Default

Thanks for the help all,

I will move this conversation to the PHP forum, cheers.
Reply
  #6  
Old September 8th, 2008, 11:55 PM
eWish's Avatar
Moderator
 
Join Date: Jul 2007
Location: Arkansas
Posts: 815
Default

Moving to PHP Forum.

--Kevin
Reply
  #7  
Old September 9th, 2008, 11:57 AM
Dormilich's Avatar
Expert
 
Join Date: Aug 2008
Location: Leipzig, Germany
Age: 31
Posts: 599
Default

Quote:
Originally Posted by dominoeffect
There must be some way to adapt this code for other URLs?
Code:
<li <?php if(is_home()){echo 'class="current_page_item"';}?>>
    <a href="<?php bloginfo('siteurl'); ?>" title="Home">Home</a>
</li>
do you know, how the is_home() function works? then you could it adapt for categories too.
Reply
  #8  
Old September 10th, 2008, 10:01 PM
Newbie
 
Join Date: Sep 2008
Posts: 8
Default

Quote:
Originally Posted by Dormilich
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
Reply
  #9  
Old September 11th, 2008, 07:06 AM
Dormilich's Avatar
Expert
 
Join Date: Aug 2008
Location: Leipzig, Germany
Age: 31
Posts: 599
Default

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
Reply
  #10  
Old September 11th, 2008, 10:58 AM
Newbie
 
Join Date: Sep 2008
Posts: 8
Default

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.

Code:
      <li <?php if(is_home()){echo 'class="current_page_item"';}?>>
          <a href="http://homepage.com" title="Home">Home</a>
      </li>

    <li <?php if(is_category('9')){echo 'class="current_page_item"';}?>>
          <a href="http://homepage.com/cat/apple" title="Posts Filed in Apple">Apple</a>

    <li <?php if(is_category('10')){echo 'class="current_page_item"';}?>>
          <a href="http://homepage.com/cat/windows" title="Posts Filed in Windows">Windows</a>
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.
Reply
  #11  
Old September 11th, 2008, 03:07 PM
Dormilich's Avatar
Expert
 
Join Date: Aug 2008
Location: Leipzig, Germany
Age: 31
Posts: 599
Default

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
Reply
  #12  
Old September 12th, 2008, 02:43 PM
Newbie
 
Join Date: Sep 2008
Posts: 8
Default

Thanks for the great advice, I truly appreciate your help!

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

Best,
Reply
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles