简体   繁体   中英

Wordpress and Internal Page Links

I'm trying to construct a Table of Content on a custom template in Wordpress. Because I already know beforehand the headings of the internal sections I want to link to I hardcoded that into the template.

My problem is that in Wordpress it doesn't scroll to that section at all? Here's the link to a page with an existing TOC section that's not working.

In terms of code, this is an illustration of what I got:

<div class="table_content">
        <h4>Table of Contents</h4>
        <ol>
            <li><a href="#test_link">Overview</a></li>
        </ol>
    </div>

Which should link to an internal section with the code:

<h2><a id="#test_link" class="internal"><?php the_title(); ?></a></h2>

Note: I'm using "ID" instead of "name" because it's deprecated in HTML5, which is the doctype I'm using.

I'm also wondering is there an easier way of doing this with jQuery?

Any help in saving my hairline would be GREATLY appreciated...

Nevermind, I'm a muppet.

It's got nothing to do with doctypes or Wordpress issues. Just my incorrect, sleep-deprived implementation of HTML.

This

<h2><a id="#test_link" class="internal"><?php the_title(); ?></a></h2>

should be

<h2><a id="test_link" class="internal"><?php the_title(); ?></a></h2>

Notice the missing "#" in the "ID" attribute, removing that makes everything work nicely :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM