WordPress.org

Ready to get started?Download WordPress

Forums

Sidebar and Pages (plus sub-pages) (3 posts)

  1. johannes_dl
    Member
    Posted 8 years ago #

    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.

  2. Doodlebee
    Member
    Posted 8 years ago #

    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>
    </li>
    </ul>

    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.

  3. johannes_dl
    Member
    Posted 8 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic