Support » Fixing WordPress » How to check if the menu links are top level ones?

  • I’m editing post-template.php in WordPress. The function start_el echoes the menu. Here I want to check if the page is a top level page so I can add a new class called “top” only to the top level pages li. How do I check if the page/link is a top level one or not? I need only this as I can do the rest.

    I’ve tried with

    if ($page->post_parent) { $css_class_litop = ‘top ‘; }
    but it doesn’t work…

    (I’ve already changed in the same class with success the classes’ names current_page_item and current_page_ancestor, current_page_parent to currentsince I use a custom jquery menu that uses this class.)

    Thanks a lot!

Viewing 5 replies - 1 through 5 (of 5 total)
  • esmi

    (@esmi)

    Forum Moderator

    Why are you editing WordPress core files?

    This is just temporary to see if I’m hitting the “right spot”. I’ll move the changes/new functions to the functions.php file once it works.

    esmi

    (@esmi)

    Forum Moderator

    You would far better off designing your function to work with the default output than tinkering with odd core files. To test whether a given page is top-level, you could check to see if it has a parent ($post->parent, if I remember correctly).

    Thanks for the reply! Unfortunately, that doesn’t work…

    I’ve managed to do it with jquery with help from stackoverflow. 😀

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to check if the menu links are top level ones?’ is closed to new replies.