• I am using the wp_list_pages() function to display the navigation for a client’s website.

    One of the pages is called ‘Blog’, and this exists as a link within the navigation.

    What I need to do is highlight this link whenever a single blog post is being viewed.

    The only way I can think of acheiving it is with JavaScript (although it would be good if there was a way do hack WP to get it working) but then I would probably need to get the permalinks to display like so:
    www.example.com/blog/sample-post01/

    Does anyone know of a way to do that?

    Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • One way to do this would be to use jQuery to add a class to the blog link when is_single() is true

    <?php if (is_single()) {   //  displaying a single blog post ?>
    <script type="text/javascript">
      jQuery("li.page-item-27").addClass('hilight');
    </script>
    <?php } ?>

    – This assumes you already have jQuery loaded.
    – page-item-27 needs to be replaced with the class name wp_list_pages assigns your blog nav item – it is the post ID of the blog page
    – you create desired stylesheet styling for li.page-item-27.hilight (again, use the number wp_list_pages is assigning – 27 is an example)

    Thread Starter 000000000

    (@pealo86)

    Ahhh yes didn’t think of that, thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Problem with 'active' states in navigation and single blog posts’ is closed to new replies.