Support » Themes and Templates » Sidebar and Pages (plus sub-pages)

  • Hi folks,

    I’m working on a theme, and I would like to know if it is possible to show on the sidebar just the parent pages, then, when that parent page is active, show above the child pages.

    Example (with no active page):
    Page 1
    Page 2
    Page 3
    Page 4

    Now with page 2 active:

    Page 1
    Page 2
    – Child Page 1
    – Child Page 2
    Page 3
    Page 4

    Ohh, and another thing, is there any function in worpress that lets me identify when a link is to an external site or not? It’s just that I wanted the external ones to have a different class.

    Thanks in advance for any help provided.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Both things can be done with CSS – but I don’t know if there’s plugins or anything for WordPress that’ll do it for ya. I’ll go ahead and tell you how to do it via CSS, and if someone knows of a plugin (or something else) that automates it a little bit better, then there you have it 😉

    Since you have to make templates for pages (generally, they’re based off of the main template – I’m going to assume that’s what you’re doing for “example” purposes), then it’s pretty simple to do the subnav thing. Just assign an id to each page’s “body” tag in the template for that page. So, using your example menu above, your body tag would look like so for each page:

    Page 1: body id=”page1″
    Page 2: body id=”page2″

    …and so on.

    Now say your navigational menu looks like so:

    <ul><li>Page 1
    <ul class="subnav"><li>subnav1</li>

    So, what you’d do is the following code:

    ul.subnav {display:none;}

    This’ll make ALL subnav elements NOT show up at all, but the parent navigational link will show just fine. To make the subnav for the page you’re on show up (in this case, Page 1), add this to the stylesheet:

    body#page1 ul.subnav {display:block;}

    Then the subnav list *only* on page 1 will appear, while the rest remain closed. You havde to go through and do this for every page, but it works just fine. Unless your site is 1000 pages, it shouldn’t be a problem to implenet a few pages of this type of code 🙂

    As for identifying external links – again, I don’t know if wordpress has a plugin or whatever, but you can create a small icon image to define external links, and then use your stylesheet to set a class to be used solely for external links. Takes a little coding, but again, works just fine.

    Thanks a lot, I think I can mug my way through it with CSS.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Sidebar and Pages (plus sub-pages)’ is closed to new replies.