|
|
|
|
Thread title: wordpress nav help |
|
|
|
|
|
Thread tools
Search this thread
Display Modes
|
|
10-01-2009, 01:05 AM
|
#1
|
Status: I love this place
Join date: Jun 2007
Location: Minneapolis
Expertise: xhtml/css, jquery, php, mysql
Software:
Posts: 533
|
wordpress nav help
I understand that I can have a nav menu in wordpress, with each link going into a different category (each post is under a specific category, so its just narrowing it all down). HOW would I be able to have a "current page"? For instance, you click on the "tutorials" link, but on your nav menu, it just looks plain, giving no sign of what page your on. With php, and only one index page, how can you accomplish this?
|
|
10-01-2009, 08:52 AM
|
#2
|
Status: Request a custom title
Join date: Dec 2005
Location: Colchester, UK
Expertise:
Software:
Posts: 4,625
|
Code:
<li<?php if(is_category('tutorials') || in_category('tutorials')) { echo ' class="current"'; } ?>><a href="<?php get_option('home'); ?>/tutorials/">Tutorials</a></li>
Sorta thing.
Basically that adds ' class="current"' to the <li>, if the user is viewing the category archive for 'Tutorials', or the post they're viewing is in the 'Tutorials' category.
|
|
10-02-2009, 10:17 PM
|
#3
|
Status: I love this place
Join date: Jun 2007
Location: Minneapolis
Expertise: xhtml/css, jquery, php, mysql
Software:
Posts: 533
|
Originally Posted by Garyrae
Code:
<li<?php if(is_category('tutorials') || in_category('tutorials')) { echo ' class="current"'; } ?>><a href="<?php get_option('home'); ?>/tutorials/">Tutorials</a></li>
Sorta thing.
Basically that adds ' class="current"' to the <li>, if the user is viewing the category archive for 'Tutorials', or the post they're viewing is in the 'Tutorials' category.
|
I understand that, but the problem is I don't know how to turn my "tutorials" category into an archive page. Not sure if thats making sense, but the closest thing I can think of is how Smashing Magazine is set up.
|
|
10-02-2009, 10:30 PM
|
#4
|
Status: Request a custom title
Join date: Dec 2005
Location: Colchester, UK
Expertise:
Software:
Posts: 4,625
|
Just add a conditional inside the loop of the archive.php template.
PHP Code:
<?php
while(have_posts()) : the_post();
if(is_category('tutorials')) {
// code for the tutorial post
} else {
// normal post code
}
endwhile;
?>
|
|
10-02-2009, 10:50 PM
|
#5
|
Status: #pugs {display: block;}
Join date: Jan 2007
Location: Chicago
Expertise: CSS, HTML, PHP
Software: Sublime Text 2
Posts: 1,187
|
Wordpress adds in a class on it's own, so you don't need to bloat it with more code.
wp_list_categories is the function you'd use within Wordpress.
Code:
<ul>
<?php wp_list_categories('&title_li='); ?>
</ul>
That will simple just display all of your categories and will hide the heading that can be output.
The classes attached that would achieve the effect you need are li.current-cat {} and li.current-cat-parent {}. Styling those will show the "current" category you're in for your navigation.
|
|
10-02-2009, 11:11 PM
|
#6
|
Status: I love this place
Join date: Jun 2007
Location: Minneapolis
Expertise: xhtml/css, jquery, php, mysql
Software:
Posts: 533
|
ahhh Looks like I need to create an archives page first ahaha
|
|
|
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
|