Support » Fixing WordPress » Menu not working to elements on other pages

  • steveoz32

    (@steveoz32)



    Hi Guys,

    I am just playing with a test wordpress site on my local machine, I am using the rational lite theme.

    The website is running under WAMP with MySQL, there is a vanilla wordpress installation in the root of the www folder. I navigate to http://localhost to bring up the site (no page extension on the URL).

    Rational lite is set to display a specific page on the home screen in the middle of it called home.

    The menu works perfectly from the default page at http://localhost

    Example from header.php:

    <div class="ske-menu" id="skenav">
    									<ul id="menu-main" class="menu">
    										<li class="landing-nav"><a href="#section1"><?php _e('Section1', 'rational-lite'); ?></a></li>
    										<li class="landing-nav"><a href="http://localhost/#section2"><?php _e('Section2', 'rational-lite'); ?></a></li>
    										<li class="landing-nav"><a href="http://localhost/index.php/#section3"><?php _e('Section3'); ?></a></li>
    										<li class="landing-nav"><a href="blog"><?php _e('Blog', 'rational-lite'); ?></a></li>

    From the default landing page it works perfect, the browser will jump to either section1, 2 or 3 on the front page, whatever method I use.

    However, if I go to the blog page from the homepage no matter what format I try to use the menu to navigate back, nothing at all happens. It will only work with the root of the site so http://localhost or other pages example http://localhost/testpage or http://localhost/homepage.

    I’ve tried:

    <a href="http://localhost/index.php/#section2"><?php _e('Section2', 'rational-lite'); ?></a>
    
    <a href="http://localhost/#section2"><?php _e('Section2', 'rational-lite'); ?></a>
    
    <a href="http://localhost#section2"><?php _e('Section2', 'rational-lite'); ?></a>

    To try and navigate back to section2 and it doesn’t even process anything (literally nothing loads, it is as if the menu is unresponsive).

    The menu however DOES work, as if I for example if I change a link on the menu to just http://localhost it will take me back to the home page?

    I’m not sure how to get it working, but it is driving me bananas, so any advice or help would be appreciated. Unless I want to just link back and forth to pages and not specific sections it won’t work.

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator t-p

    (@t-p)

    Please identify exactly which theme you are using and then post in that theme’s dedicated forum via its page in the Theme Repository so the theme’s developers and support community can help you with this.

    For pro or commercial product support please contact the author directly on their site. Commercial products are not supported in these forums.

    Moderator bcworkz

    (@bcworkz)

    IMO, the issues you encountered are universal to WP and not related to any specific theme. While rare in these forums, sometimes moderators disagree 🙂

    First of all, never use relative links in WP, such as <a href="#section1">. Always provide full domain/path links.

    If your section skip links were on any other page besides home, you wouldn’t have any trouble with links like <a href="http://localhost/my-post-slug/#section2">

    The trouble is in home page links, with URLs like http://localhost/#section2, there is no post slug, so WP tries to find a post slug matching “#section2”. Of course this fails.

    I’m assuming you have selected a static home page in settings, and do not have a blog archive as home page. Thus the home page actually does have a slug even though it’s not used. Still, you can request the page using its slug. WP will still output the correct page, rewriting the address bar to the usual domain only URL.

    Untested, but I believe requesting the home page slug along with section skip link will work as it should. Lets say you home page slug is “foobar”. Your menu home page link to section 2 should then be <a href="http://localhost/foobar/#section2">. You may have to switch to a different page as home page to learn the proper slug, then switch back.

    If your home page is a blog listing, you likely would need to create a custom page template that outputs a blog listing. Then set your site to use this page as a static home page.

    Please demarcate any code included in forum posts with backticks, or use the code button. Failure to do so corrupts and obfuscates the very code you are trying to use in the way of illustration. I fixed the code in your OP so we can see the underlying link HTML. Because the forum’s parser automatically linkifies URL’s, the resulting code blocks may still not match your original intent.

    steveoz32

    (@steveoz32)

    Thanks both for taking the time to reply, the advice and thanks for fixing the code, I’ll remember that in future.

    The permalink for the homepage was a little broken, so I fixed it.

    BCworkz you are correct, if I amend the menu so that it links to

    http://localhost/home/#section1

    Then it continues to work on the home page, but from the blog page it still will not work as expected.

    Yet if I paste the link directly into the browser it works.

    It’s very odd the theme’s menu will navigate to a page but it won’t navigate to a section of a page, it simply refuses to do anything. I can only assume this may be a problem with the theme’s code.

    I still find it bizarre that it will not work though it’s simply a href…

    <li class="landing-nav"><a href="http://localhost/home/#section1"><?php _e('section1'); ?></a></li>

    Thanks.

    • This reply was modified 1 month ago by  steveoz32.
    steveoz32

    (@steveoz32)

    So it seems there is something odd in the way that the menu is behaving, example, the link is clearly there, if I right click and open link in new window it takes me to where I need to go.

    The menu for some reason simply will not open another section on another page for whatever reason.

    I’ll keep digging.

    **Edit**

    So I created a new menu, I was using the alternative menu written in the header.php and figured it may be buggy. I created a wordpress menu, then published it as the main menu and replaced the theme’s standard fallback menu > same result.

    I wonder if it is because I am trying to link to class ID’s and those classes do not exist until the page is loaded? It works with all other sites I have made manually, but I am wondering if wordpress HAS to have it’s own anchor or ID for the elements defined in it’s directory before it will link internally to them (as I mentioned copy and paste the link in a new window it will work, so makes me think it is an internal issue with wordpress code itself).

    The theme has a “featured-box” section on the front page, so I try to link to that ID:

    <div id="featured-box" class="skt-section">
    	<div class="container">
    		<div class="mid-box-mid row-fluid"> 

    Of course it fails as the others do. If the page is loaded, no problem, the menu will link to #featured-box however I want to format it. From another page, even using the static page that is displayed which is “home” followed by the ID will not work.

    Thanks.

    • This reply was modified 1 month ago by  steveoz32.
    • This reply was modified 1 month ago by  steveoz32.
    Moderator bcworkz

    (@bcworkz)

    I tried the same scenario on my site and the skip link works fine. Be sure the ID attribute only occurs once on the page. Multiple matching ID values are invalid HTML and will cause skip link and JS problems.

    Try switching to a twenty* default theme and see if that resolves the issue. If it does, it turns out t-p was right all along and you should seek assistance through your theme’s support.

    If you still have trouble with a default theme active, deactivate all plugins as a test. The issue should resolve itself now. Start restoring your plugins, one at a time, testing after each. When the problem recurs, the last activated plugin is the cause. Seek assistance at that plugin’s support channel.

    Thanks @bcworkz I’ve been crazy busy at work so not had chance to get back to this until this evening, but will take your advice and do some more digging! When I have the solution I will post back 🙂

    Oh also there is not a forum for the rational-lite theme, hence continuing the thread here.

    Many thanks,

    Steve

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.