• squill1959

    (@squill1959)


    Hi.

    This plugin is exactly what I am looking for, but I am trying to understand the logic required for the visibility field.

    I have added the following function to my functions.php file:

    function is_child($pageID) {
    global $post;
    if( is_page() && ($post->post_parent==$pageID) ) {
    return true;
    } else {
    return false;
    }
    }

    and I am trying to use the following condition to display the menu item if the parent page is active or if a child of the parent page is active.

    is_page(221) or is_child(221)

    However it does not work, so if the function is correct, my logic is faulty.

    Any suggestions would be appreciated.

    https://www.ads-software.com/extend/plugins/menu-items-visibility-control/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter squill1959

    (@squill1959)

    Hi again.

    The answer is I am wrong on two counts!

    The is_child function doesn’t do what I expect and my logic syntax flawed.

    Rather than ‘or’ it should be ‘||’.

    In then end I used:

    is_page(array(‘parent-page-name’,’peer-1-name’,’peer-2-name’))

    which works, but is a bit unweildy as you have to manually add a new peer page to each menu item in a section.

    What I am trying to achieve is to show the children of a menu item if either the parent page is visible or any of the children of that parent page are visible. An is_peer(me) function.

    Plugin Author shazdeh

    (@shazdeh)

    Hi,
    if you have lots of menu items I would suggest to write a custom walker for wp_nav_menu function.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘is_child function’ is closed to new replies.