Set current page on index.php when I use categories in wordpress menu?

I use categories to the main navigation in wordpress. To show my category “Home” (start page), I use the following code in index.php. “Home” is category 4.

<?php if ( have_posts() ) : ?> <?php query_posts("cat=4"); //set cat 4 to start page ?>
            <?php /* Start the Loop */ ?>

The problem is that when someone visits my site are “Home” not marked as current page. But if a click on “Home” is it highlighted as current page.

Read More

How do I set category home as the current page when someone visits my site? Can i include the css in my php code above?

Have the following in in my css that works when you click on a link (category) in the main menu, but not when someone visits the web page without clicking in the menu.

.main-navigation .current-menu-item > a,
.main-navigation .current-menu-ancestor > a,
.main-navigation .current_page_item > a,
.main-navigation .current_page_ancestor > a {
    color: #ffffff;
            background-color: #f68a1f;
}

My menu code looks like this (use wordpress menu)

<nav id="site-navigation" class="main-navigation" role="navigation">
            <h3 class="menu-toggle"><?php _e( 'Meny', 'twentytwelve' ); ?></h3>
            <div class="skip-link assistive-text"><a href="#content" title="<?php esc_attr_e( 'Skip to content', 'twentytwelve' ); ?>"><?php _e( 'Skip to content', 'twentytwelve' ); ?></a></div>
            <?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) ); ?>
        </nav><!-- #site-navigation -->

Related posts

Leave a Reply

1 comment

  1. Instead of using index.php, create a new “Page of Posts” page template as described here: http://codex.wordpress.org/Pages#A_Page_of_Posts

    In that template you use the query_posts("cat=4"); code to only have it show the posts from that category.

    Then you make a new page in your WordPress dashboard, call it anything you like, and set its template (in the “Page Attributes” block on the edit page) to your newly created template.

    Last of all, in your Settings > Reading set “Front page displays” to “A static page”, and select your newly created page as the front page.

    This way you use the built-in functionalities of WordPress to create a custom page with specific types of contents in it, and still have it recognize that the page is active when you’re on it.