WordPress.org

Ready to get started?Download WordPress

Forums

Shortcode Count (3 posts)

  1. julian.weinert // www.csundm.de
    Member
    Posted 2 years ago #

    Hey guys!

    I'm working on a plugin that creates HTML Code via a shortcode.
    Now I want to identify the created HTML when the shortcode gets called twice or more often.

    Like:

    <div class="myClass-0"></div>
    <div class="myClass-1"></div>

    Is there a way to count how many times a specific shortcode got called?

    I tried this PHP code:

    if(!$count)
    {
        $count = 0;
    }
    else
    {
        $count = $count + 1;
    }

    But it seems as the variable gets deleted after calling the shortcode one time.
    I also tried global variables… But all this didn't seem to work.

    Hope somebody can help me!
    Greets
    J.

  2. Yong
    Member
    Posted 2 years ago #

    I have the same question about this too, have you get solutions?

    thanks.

  3. julian.weinert // www.csundm.de
    Member
    Posted 2 years ago #

    Oh yea!
    I got the solution but forgot to answer here.

    So here you go:

    static $count;
    if(!$count)
    {
        $count = 0;
    }
    $count++;

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 2 years ago by julian.weinert // www.csundm.de
  • Latest reply from julian.weinert // www.csundm.de
  • This topic is not resolved
  • WordPress version: 3.3.1