1

我有一个条目列表,我试图在顶部创建一个可以单击的标题列表,以便页面滚动到正文。以下内容不起作用,因为当我使用 entry_id 时,它正在写出整个 URL/entry_id

<div class="list">
    {exp:channel:entries channel="mychan" category="2"}    
        <div class="mytitle"><a href="{entry_id}">{title}</a></div>
    {/exp:channel:entries} 
</div>

{exp:channel:entries channel="mychan" category="2"}    
    <div class="ele">
        <div class="mytitle"><a href="#entry_id">{title}</a></div>
        <div class="mybody">{mybody}</div>
     </div>
{/exp:channel:entries}   
4

1 回答 1

3

It's not writing out the entire URL/entry_id. The href is only the entry_id, which the browser automatically converts to http://your-site.com/entry_id. For an internal link, it needs have a # symbol.

Also, internal link names have some other requirements:

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

So they can't just be a number; you need to start with a letter at least.

So in your first {exp:channel:entries} loop linking to the entry, change the link href to this (or something similar):

<a href="#entry_{entry_id}">{title}</a></div>

And in the second loop, repeat that (without the #) as an ID on your wrapping div:

<div class="ele" id="entry_{entry_id}">
  ...
</div>
于 2012-09-10T15:59:57.943 回答