crisrealwp
Member
Posted 1 year ago #
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!
Why are you editing WordPress core files?
crisrealwp
Member
Posted 1 year ago #
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.
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).
crisrealwp
Member
Posted 1 year ago #
Thanks for the reply! Unfortunately, that doesn't work...
crisrealwp
Member
Posted 1 year ago #
I've managed to do it with jquery with help from stackoverflow. :D