Support » Plugins » Any one wants to help TOC plugin into the loop ?

  • In here, there is a plugin which allows you to add a table of content (TOC), to your post (where you will put: <!–TOC–> in the post)

    But, I wish this to all my posts,
    So I either need a mess “put XXX line in the begining of all my post”.
    That some one will upgrade the plugin so it could be called from the loop (which will be a great add in to the next WP release)


Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator Samuel Wood (Otto)

    (@otto42) Admin

    I’m confused. Do you just want this to be automatically added to the top of every one of your posts? If so, that’s easy. This is the quick and dirty way, but it’ll work.

    At the very bottom of the plugin, you’ll find this line:
    $post->post_content = $this->the_content($post->post_content);

    Change it to this:
    $post->post_content = $this->the_content("<!--TOC-->".$post->post_content);

    Done and done.

    HELPED allot 10X !

    (10x 10x 10x ! )

    mmm – one more question –

    Is there a way to make the plugin ignore “blank” headers ?!

    You mean headers with nothing between the Hx and /Hx? You can do that with a small edit to the plugin code.

    Change this line (around line 96):
    $regex = ‘#<h([1-6])(.*?)>(.*?)</h\1>|<!–nextpage–>#’;
    to this:
    $regex = ‘#<h([1-6])(.*?)>(.+?)</h\1>|<!–nextpage–>#’;

    Notice that the second * became a +.

    Ok, one more questions then – and a little trickier I think 😉

    How about making the list numbering nested as well?

    1. Section 1
    1.1 Sub-Section 1
    1.2 Sub-Section 2
    2. Section 2

    Hi CharlesKrause,
    The Plugin already those this when incontering a <H4>, as follows:


    And thanks Nazgul, But unfortunetly, it dosn’t seem to do the trick. Any other suggestions ??

    Hmm… it indents them, yes.

    But I meant change the numbering scheme.

    Right now, the output is

    1. Section #1
    — 1. Sub-Section #1
    — 2. Sub-Section #2
    2. Section #2
    — 1. Sub-Section #1
    —- 1. Sub-Sub-Section #1
    —- 2. Sub-Sub-Section #2
    — 2. Sub-Section #2

    Ideally, what I’d like to see (and may have to code myself) is something like:

    1. Section #1
    — 1.1. Sub-Section #1
    — 1.2. Sub-Section #2
    2. Section #2
    — 2.1. Sub-Section #1
    —- 2.1.1. Sub-Sub-Section #1
    —- 2.1.2. Sub-Sub-Section #2
    — 2.2. Sub-Section #2

    Note the change in the numbering of the sections.

    I see.
    Have fun :).

    p.s -> the guy that made the plugin is giving answers in his forum, it might be worth a shot :

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Any one wants to help TOC plugin into the loop ?’ is closed to new replies.