WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Change class="" based on page

[Resolved] Change class="" based on page

  • I am setting my navigation elements to change it’s class to class=”selected” when you are on a specific page in the site. I have it working, except for the blog (home.php) page. I have set the “posts page” to “blog” in the Reading Settings, and here is the code that tells each page (or child of a page) which navigational section to change the class for

    //* WORK *//
    $work_selected = '';
    if (is_page('work') || $post->post_parent == '39') {
      $work_selected = 'selected';
    } else {
      $work_selected = '';
    }
    //* BLOG *//
    $blog_selected = '';
    if (is_page('blog') || $post->post_parent == '64') {
      $blog_selected = 'selected';
    } else {
      $blog_selected = '';

    Again, the WORK version does indeed work, as does the other pages on the site. For some reason, the BLOG page does not work. Any help?

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] Change class="" based on page’ is closed to new replies.