• How can I make a shortcode that echoes the number of ocurrence in each post?

    Something like inserting:

    [foo /] [foo /] [foo /]

    And render:

    1 2 3

Viewing 2 replies - 1 through 2 (of 2 total)
  • Michael

    (@alchymyth)

    function foo_counter($atts) {    // [foo] keeps adding 1 everytime it is called in a post
    static $foo_count=0; $foo_count++; return $foo_count;
    }
    add_shortcode ('foo', 'foo_counter');

    use [foo] in the post

    Thread Starter Andrés Sanhueza

    (@atoon)

    That works, thanks.
    Is there a way to reset the count in each post (like when more than one appear in a loop)?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Shortcode that counts each ocurrence of it in a post’ is closed to new replies.