0

I have this structure for example:

Page 1
  Sub-Page 1.1
    Sub-Page 1.1.1
    Sub-Page 1.1.2
    Sub-Page 1.1.3
  Sub-Page 1.2
    Sub-Page 1.2.1
    Sub-Page 1.2.2
    Sub-Page 1.2.3
Page 2
  Sub-Page 2.1
    Sub-Page 2.1.1
    Sub-Page 2.1.2
    Sub-Page 2.1.3
  Sub-Page 2.2
    Sub-Page 2.2.1
    Sub-Page 2.2.2
    Sub-Page 2.2.3

I would like to have a sidebar navigation which has all items from the root-page and the curent page should be marked with some css-class. For example I'm on Page 2.2.2, the navigation should look like this:

Sub-Page 2.1
  Sub-Page 2.1.1
  Sub-Page 2.1.2
  Sub-Page 2.1.3
Sub-Page 2.2
  Sub-Page 2.2.1
  Sub-Page 2.2.2.current_page
  Sub-Page 2.2.3

Second Example: I'm on Page 1.2:

Sub-Page 1.1
  Sub-Page 1.1.1
  Sub-Page 1.1.2
  Sub-Page 1.1.3
Sub-Page 1.2.current_page
  Sub-Page 1.2.1
  Sub-Page 1.2.2
  Sub-Page 1.2.3

I looked through the codex but I could not find anything which fits. Any Ideas?

1
  • 1
    If the answer satisfies your Question, don't forget to accept the answer by clicking the tick mark on the left to the Answer. :) – Mayeenul Islam Apr 12 '14 at 7:31
3

wp_list_pages will output all of the pages, posts, and CPTs that you wish. You even have control over the CSS classes, some of which are already there:

All list items (li) generated by wp_list_pages() are marked with the class page_item. When wp_list_pages() is called while displaying a Page, the list item for that Page is given the additional class current_page_item.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.