WordPress.org

Ready to get started?Download WordPress

Forums

Display different pages in nav bar based on what page you're on (7 posts)

  1. gemanshi
    Member
    Posted 5 years ago #

    Hi,

    I'm using the blueprint theme and wp-e-commerce for an online store I'm trying to put together. Currently, I have the nav bar displaying the following pages along the top:

    Home | Artists | Store | Contact

    Is there a plugin or hack that, if a person clicks on the Store link the nav bar dislays different links such as:

    Home | Store | Checkout | Your Account

    Once they clicked Home they would go back to the normal nav bar layout. Hopefully what I'm describing makes sense. The reason I would like to do this is because currently, some of the subpages like Checkout and Your Account don't display even when you click on store. I'd prefer that they're only visible when you click on the Store page.

    Thanks.

  2. jasonmassengale
    Member
    Posted 5 years ago #

    I'm no pro and tend to hack my way through stuff until I figure it out. This is how I accomplished what I think you're asking.

    If the pages Checkout and Your Account are children of Store, they would appear on the store page.

    <?php
    $thepostid = $post->ID;
    if ($thepostid!=0)
    wp_list_pages('title_li=&amp;depth=1&amp;sort_column=menu_order&amp;child_of='.$thepostid);
    ?>

    You might want to look at the page id for store (find the id that shows up when you mouse over the page from the edit pages screen). Replace the line above:
    if ($thepostid!=0)
    with:
    if ($thepostid==<em>X</em>)
    where X is the id number of the Store page.

  3. jasonmassengale
    Member
    Posted 5 years ago #

    Didn't mean to have the in there. This is what it should be replaced with:
    if ($thepostid==X)
    where X is the id number of the Store page.

  4. gemanshi
    Member
    Posted 5 years ago #

    This looks great. Thanks so much for the response. I do have one other question (probably a stupid one) though. Where should I put this code? The header file? Sorry about the question, just trying to hack/stumble through this myself.

  5. gemanshi
    Member
    Posted 5 years ago #

    Alright, I placed the code in the header file and I get ALL the pages (parents and children) displayed at all times.

  6. jasonmassengale
    Member
    Posted 5 years ago #

    Did you change it so your unique post id is substituted for the "X"?

    This line:
    if ($thepostid!=0)
    basically says if the post (or page) id is not equal to 0. In other words, you are on a post or a page.

    Two parts of that line need to change for it to work the way you want:

    • The != needs to change to = (looks like I put two = signs before when I think it should be 1 = sign)
    • The '0' needs to change to whatever the unique post id of the store page is.
  7. gemanshi
    Member
    Posted 5 years ago #

    I have:

    <?php
    $thepostid = $post->ID;
    if ($thepostid=118)
    wp_list_pages('title_li=&amp;depth=1&amp;sort_column=menu_order&amp;child_of='.$thepostid);
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic