WordPress.org

Ready to get started?Download WordPress

Forums

Menu Customisation - Urgent (24 posts)

  1. Alec Weekes
    Member
    Posted 2 years ago #

    Greetings WordPress Community,

    I'm looking to alter the way in which my Menu operates. You can view what I am trying to achieve at: http://cleaning.greenchoicegroup.com

    I'm trying to have my menu system display Home Page only on any Sub Pages that I've created. In the link above, you can see that there is no "Home Page" on the front, yet I wish there to be on any of the sub-pages I create within that site.

    The purpose of this is to have a Home Page link on any sub-pages allowing them to return to the Home Page, without it displaying on the Home Page, causing confusion.

    Here is the code that handles my menu system.

    <div id="menu" class="alignleft">
                                    <?php if( function_exists('wp_nav_menu') && has_nav_menu('primary'))
                                        {
                                                    wp_nav_menu( array('menu_id'=> '','container'=>''));
                                        }
                                               else {
                                                    echo '<ul>';
                                                            wp_list_pages('title_li=');
                                                    echo '</ul>';
                                               }
                                        ?>
    			</div>
  2. Vee
    Member
    Posted 2 years ago #

    Hi,

    Simplest way is use the the home link before you pages list:

    <ul>
    <li><a href="<?php get_settings('home'); ?>">Home</a></li>
        <?php wp_list_pages('title_li='); ?>
    </ul>
  3. Alec Weekes
    Member
    Posted 2 years ago #

    Vishal,

    Firstly, as far as I've tried whenever using <li> or </li>I get errors related to them.

    Along with this, I am wanting to hide the "Home" on any of my Home Pages. But still show it on the Sub Pages.

    I'm thinking something along the lines of an if statement to load either my first, or second menu dependant on which page they're on.

    If they're on page one for example then Menu 1 is loaded, however page 2 loads Menu 2.

  4. Vee
    Member
    Posted 2 years ago #

    What is the error you are getting.

    Use if(!is_home()) for show the home on other pages only.

    Thanks

  5. Alec Weekes
    Member
    Posted 2 years ago #

    How would you structure that then Vishal?

    I'm trying to include the if(!is_home()) somewhere in the code I showed above, and I just displays the entire menu i've got.

    Edit:

    I'm getting the following error using your suggestion:

    Parse error: syntax error, unexpected '<' in [directorylistings]/header.php on line 94

  6. Vee
    Member
    Posted 2 years ago #

    Use this

    <div id="menu" class="alignleft">
     <?php if( function_exists('wp_nav_menu') && has_nav_menu('primary'))
       {
          wp_nav_menu( array('menu_id'=> '','container'=>''));
       }
           else {
                echo '<ul>';
    	     if(!is_home()) echo "<li><a href=".get_settings('home').">Home</a></li>";
               wp_list_pages('title_li=');
               echo '</ul>';
                }
      ?>
    </div>
  7. Alec Weekes
    Member
    Posted 2 years ago #

    Thanks Vishal,

    The menu is appearing as it was originally, but it appears that it isn't hiding the Home Page link at all.

    It seems as if the if(!is_home()) isn't working or doing its job properly. It shows on all the child pages as intended, but still shows on the Home Page.

    Would is_page('x') work better?

  8. Vee
    Member
    Posted 2 years ago #

    Yes you can use is_page(), add page by id, page name.

    check this : http://codex.wordpress.org/Function_Reference/is_page

  9. Alec Weekes
    Member
    Posted 2 years ago #

    Do you suspect that there is a spelling error within it however? I've just noticed my coding program is colouring Home as if something isn't closed.

    Could you check the: .get_settings('home'). section as fully intentional, I've not used .get_settings before

  10. Vee
    Member
    Posted 2 years ago #

    Use get_option('home')

    and check this for reference
    http://codex.wordpress.org/Function_Reference/get_option

  11. Alec Weekes
    Member
    Posted 2 years ago #

    Doesn't appear to work, despite my best effort I still get either errors or the Home Page isn't showing.

    Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in [directorylistings]/header.php on line 98

  12. Vee
    Member
    Posted 2 years ago #

    post you header file code

  13. Alec Weekes
    Member
    Posted 2 years ago #

    New Error after some changes:

    Parse error: syntax error, unexpected '<' in [directorylistings]/header.php on line 96

    Here is the entire chunk of code I am using:

    <div id="menu" class="alignleft">
     <?php if( function_exists('wp_nav_menu') && has_nav_menu('primary'))
       {
          wp_nav_menu( array('menu_id'=> '','container'=>''));
       }
           else {
                echo '<ul>';
    	     if(!is_home())
    	     	<li><a href="get_option('home')">Home</a></li>;
               wp_list_pages('title_li=');
               echo '</ul>';
                }
      ?>
    </div>
  14. Vee
    Member
    Posted 2 years ago #

    Replace with this, you are making wrong syntax.

    <div id="menu" class="alignleft">
     <?php if( function_exists('wp_nav_menu') && has_nav_menu('primary'))
       {
          wp_nav_menu( array('menu_id'=> '','container'=>''));
       }
           else {
                echo '<ul>';
    	     if(!is_home())
    	     	echo "<li><a href=".get_option('home').">Home</a></li>";
               wp_list_pages('title_li=');
               echo '</ul>';
                }
      ?>
    </div>
  15. Alec Weekes
    Member
    Posted 2 years ago #

    Still isn't working.

    As you can see in this image (http://i.imgur.com/XPdW3.jpg) the ('home').">Home</a></li>"; appears to be coloured, as if something isn't closed or working.

    I am thankful for you assistance so far, and I appreciate all the help. I've never encountered these issues before : /

  16. Vee
    Member
    Posted 2 years ago #

    In the line 95, according to your image, remove the semi-colon and blank space after closing bracket tag. This is the starting of if statement. Check the code i give above.

  17. Alec Weekes
    Member
    Posted 2 years ago #

    It still doesn't show Home on the Home Page. I'll try it with a is_page(' ')

  18. Vee
    Member
    Posted 2 years ago #

    You want to show home link on home page menu?

  19. Alec Weekes
    Member
    Posted 2 years ago #

    Neither of the functions is_page('2') or is_front_page() are working.

    This is very odd, it is almost as if it is completely ignoring the line of code : /

  20. Alec Weekes
    Member
    Posted 2 years ago #

    Basically, I am running a Mutlisite Network for a Client.

    They wish for me to remove the Home Page link displayed on any of the Home Pages, and have it present only on the child pages.

    So for example: Home Page | Services | Contact Us is how the menu looks now, but we only want the Home Page link to show on the child pages, not the Home Page of the site.

  21. Vee
    Member
    Posted 2 years ago #

    Try, bloginfo('wpurl')

    or can you give me the site link for check

  22. Alec Weekes
    Member
    Posted 2 years ago #

    Sure.

    I'm trialing it on the Restaurant Mini-Site at the moment, you can view other pages to see what we've got, compared to what we want to achieve.

    http://cleaning.greenchoicegroup.com/restaurant-cleaning/

  23. Alec Weekes
    Member
    Posted 2 years ago #

    I'm starting to believe that the echo is trying to call the entire line, and so repeating another link within an echo is causing issues.

    As seen in the original image I posted, Home is coloured to indicate it is part of a function, rather then just text.

    Update: To get the Home Page to show up, I need to change to code and remove the " ". It looks like: echo <li><a href="bloginfo('wpurl')">Home</a></li>;

    However doing so throws up the error I posted earlier, regarding the Parse Error.

  24. Alec Weekes
    Member
    Posted 2 years ago #

    Some research indicates the use of HTML hyperlinks in Php is not an easy task. Using " or ' closes or starts new sections within Php (as we know), so by including a Hyperlink we close and reopen the Php command.

Topic Closed

This topic has been closed to new replies.

About this Topic