Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

has_children class exists for a parent when all children are actually hidden #18

Open
mchev2 opened this issue Jan 13, 2016 · 6 comments

Comments

@mchev2
Copy link

mchev2 commented Jan 13, 2016

For the navigation widget, we noticed that has_children class for a navigation li is added even when all the children are hidden (visibility hidden). It seems like the widget is only checking if there are children and then adding has_children class. It should add has_children only if the parent has any visible children.

@awbauer
Copy link
Collaborator

awbauer commented Jan 21, 2016

Hi @mchev2,
Thanks for reporting that. We'll have to do a bit of investigation regarding the impact to existing sites before setting a fix here.

@mchev2
Copy link
Author

mchev2 commented Feb 29, 2016

Hi @awbauer, is there any update on this issue? If there is anything that I can help with please let me know. Thank you.

@BUWebTeam
Copy link

Mentioned on Slack by Andrew Bauer in #cms. View the logs ➡️

@awbauer
Copy link
Collaborator

awbauer commented Mar 8, 2016

@mchev2 Still taking a look into this. Will update when we have a fix ready to go.

@BUWebTeam
Copy link

Mentioned on Slack by Andrew Bauer in #wp-dev. View the logs ➡️

@mchev2
Copy link
Author

mchev2 commented May 13, 2016

We came up with this solution to add an extra class 'has_visible_children'.

function bu_navigation_item_class_visible_children($item_classes, $page){
  if( bu_navigation_page_has_visible_children($page->ID) ){
    $item_classes[] = 'has_visible_children';
  }

  return $item_classes;
}
add_filter('bu_navigation_filter_item_attrs', 'bu_navigation_item_class_visible_children', 10, 2);

function bu_navigation_page_has_visible_children($page_id){
  static $pages;

  if( !$pages ){
    // Get all visible pages
    $args = array(
      'post_type' => 'page',
      'posts_per_page' => -1,
      'fields' => 'id=>parent',
      'meta_key'   => BU_NAV_META_PAGE_EXCLUDE,
      'meta_value' => 0
    );

    $query = new WP_Query( $args );
    $pages = $query->get_posts();
  }

  // If the page_id is not a parent of any of the visible pages, then it does not have any visible children
  return !!array_search($page_id, $pages);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants