Viewing 4 replies - 1 through 4 (of 4 total)
  • Try the developer help notes under the help tab. This will give you the TOC index so you’ll still need to call the_content so it can add the anchors into the headings.

    Thread Starter btzitney

    (@btzitney)

    I hate to be that guy, but could you explain that a little further? In what order do I call the index and then call the_content? Is the toc content not showing up because I’m calling it before the_content? And is it the following code that gives me the actual toc:
    echo '<ul id="my_toc">' . toc_get_index($content = '', $prefix_url = '') . '</ul>';

    Thread Starter btzitney

    (@btzitney)

    Ok I’ve got it to work using do_shortcode() but the only thing it prints on the pages is <!--TOC-->

    Provided you are in the loop, you can retrieve the index with plainly $toc = toc_get_index();

    You can then do whatever you want with $toc (change it, echo it, etc) but don’t forget the starting and closing ul tag. Seeing that you stored it in a variable, you can use it outside of the loop.

    Later on, you’ll still need to call the_content() so it can output the content with all of the anchors.

    Don’t use do_shortcode if it’s only outputting that.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘adding toc in template file’ is closed to new replies.