WordPress.org

Ready to get started?Download WordPress

Forums

Any one wants to help TOC plugin into the loop ? (9 posts)

  1. talgalili
    Member
    Posted 7 years ago #

    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)

    http://fucoder.com/code/toc-generator/

    But, I wish this to all my posts,
    So I either need a mess "put XXX line in the begining of all my post".
    OR,
    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)

    10X,
    Tal,

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    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.

  3. talgalili
    Member
    Posted 7 years ago #

    HELPED allot 10X !

    (10x 10x 10x ! )

  4. talgalili
    Member
    Posted 7 years ago #

    mmm - one more question -

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

  5. Nazgul
    Member
    Posted 7 years ago #

    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 +.

  6. CharlesKrause
    Member
    Posted 7 years ago #

    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

  7. talgalili
    Member
    Posted 7 years ago #

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

    h3
    --h4
    --h4
    h3
    h3
    --h4
    h3

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

  8. CharlesKrause
    Member
    Posted 7 years ago #

    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.

  9. talgalili
    Member
    Posted 7 years ago #

    I see.
    Have fun :).

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

Topic Closed

This topic has been closed to new replies.

About this Topic