link to a section on the page with WP menu

I don't know much php but I have a parallax template and different sections which are technically pages created in wp-admin. So for example page 2 is:

    <!-- Section #2 -->
<section id="middle" data-speed="4" data-type="background">
        <div class="container">
            <?php query_posts('page_id=' . of_get_option('home_page_2', 'no entry' )); while (have_posts()) : the_post(); ?>
                <?php global $more;   
                $more = 0;
                the_content(""); ?>
            <?php endwhile; ?>

Now I want to modify the main wp menu at the top to link to this section. I have tried doing it with html so I wrapepd that whole section around an <a id="2"> tag and recalling it in the menu with and this works partially BUT it now sees that whole section as a hyperlink thus messing up its formatting. Is there another way of doing this with php?


I'm not sure if I understood what you need correctly, but in order to link to an element on the page, you could do the following:

  • Option 1: Set an id attribute to the element:
<section id="mysection">...</section>
  • Option 2: create an empty anchor tag with an id attribute at the top of the section element:
<a id="mysection"></a>
    <h2>My Section</h2>
    <!-- ... -->

Then target the section's id with your anchor tag:

<a href="#mysection">Go to My Section</a>

JSFiddle Demo.

Need Your Help

uncaught exception: out of memory in Ajax Process

javascript php jquery ajax

I got a problem I am submitting a simple form that has a small data and when I checked in the console tab the URL of ajax seems to be working but after the ajax was processed it will alert an error...

multiple background pics in css

css background hover

this is what im trying to do...