Forums

Showing a menu on certain pages (10 posts)

  1. noobnoob
    Member
    Posted 3 years ago #

    Hi,

    How could i add a menus depending on the page? The sidebar.php has a certain conditions and i'd like to use similar on my own menus.

    I'd like to be able to:
    -Show menu on certain pages <-- related to that particular page
    -Have a few different menus for different pages

    Is this possible / easy to do?

    THANKS!

    PS. I'm thinking of using this as CMS.

  2. filosofo
    Member
    Posted 3 years ago #

    Each page has an ID value, which you can see under the Manage tab. So if you want a certain menu for the page with ID 4, you could do something like the following:
    if (4 == $id) {
    [echo menu]
    }

  3. guillaumeb
    Member
    Posted 3 years ago #

    What would you piece of code would you use so that the sidebar does not display on a certain page??
    thank you

  4. Bricolou
    Member
    Posted 3 years ago #

    I'm not sure this is the best solution but faced with the same problem I resolved it using a second template and replacing
    < ? php get_sidebar(); ? >
    with
    < ? php include( TEMPLATEPATH . '/different sidebar/sidebar.php'); ? >
    after creating a directory named "different sidebar" with sidebar.php file in it.
    You can repeat the operation as many times as you wish.
    (delete the spaces to get it right)

  5. doodlebee
    Member
    Posted 3 years ago #

    You can use CSS and filo's suggestion to NOT display a menu on a certain page. In your template for that page, just set your menu (whatever it is in your stylesheet) set to "display:none;" and it won't show on your page.

  6. maerk
    Member
    Posted 3 years ago #

    doodlebee: doing that would remove it from all over the site.

    One solution might be to do the following.

    In your page.php file, just have <?php get_sidebar(); ?> as usual, but then in your sidebar.php file, you could do this:

    <?php if ( is_page('X') : ?>
    <!-- HTML for page with ID of X -->
    <?php elseif ( is_page('Y') : ?>
    <!-- HTML for page with ID of Y -->
    <?php elseif ( is_page('Z') : ?>
    <!-- HTML for page with ID of Z -->
    <?php else : ?>
    <?php get_sidebar(); ?>
    <?php endif; ?>

    You can repeat as many of those elseif statements as you like for all your various pages. The page ID can be found on Manage > Pages.

  7. doodlebee
    Member
    Posted 3 years ago #

    >>doodlebee: doing that would remove it from all over the site.<<

    Not if you put it *only* in the CSS for the page you don't want it to show up in...

  8. maerk
    Member
    Posted 3 years ago #

    That's true, but you'd have to specify the right link to the right CSS file, which would involve detecting which page you were on anyway ;D

  9. doodlebee
    Member
    Posted 3 years ago #

    Well, I agree with that - but if it's just one or two pages, you could simply put that CSS within an inline style directly on the template itself :) If it's quite a number of pages, then yeah, you'd *so* need detection!

  10. noobnoob
    Member
    Posted 3 years ago #

    Thanks for the replies!

    I'll try the Maerk's solution.

Topic Closed

This topic has been closed to new replies.

About this Topic