jump to current_page_item
-
Hello,
I have my wp_list_pages inside a scrollable div.
Is there any way I can make the div scroll down to the current_page_item at page load? (so the current page link is visible to the user).
Thank you for your help!
-
Javascript, but there might be other ways to do it. An URL would help.
Have a look at https://developer.mozilla.org/En/DOM/Element.scrollIntoView
Thank you. I will try that.
From what I understand “scrollIntoView” needs an objectID as target.
But wp_list_pages generates “current_page_item” as a Class.Is there anyway arround this?
Thank you all.
anyone?
I figured out what I want to to do is to add an anchor to the link (on the list generated by “wp_list_pages”) that corresponds to the the current page (current_page_item).
Does anyone know how to achieve this?
Thanks a lot!
I got it!
In case someone has the same need, you can edit classes.php in wp-includes folder.
add a new variable (ex. $anchorname) to:
if ( $page->ID == $current_page ){ $css_class[] = 'current_page_item'; $anchorname = 'link_name';}then add it to $output below like this:
$output .= $indent . '<li class="' . $css_class . '"><a>ID) . '" title="' . esc_attr(apply_filters('the_title', $page->post_title)) . '" name="' . $anchorname . '">' . $link_before . apply_filters('the_title', $page->post_title) . $link_after . '</a>';if you check your output your link now has a name=”link_name” 🙂
Hope this helps someone else.
The topic ‘jump to current_page_item’ is closed to new replies.