407 posts
  • Top Monthly Author
  • Weekly Top Seller
  • Elite Author
  • Author Level 9
+7 more
EugeneO
says

I have shortcodes used to create styled tables:

[styled_table]

[styled_column] [/styled_column]

[styled_column] [/styled_column]

[styled_column] [/styled_column]

[/styled_table]

In the above example the table would be created with three columns.

The problem I’m having is that I need to automatically count the number of [styled_column] shortcodes inside the [styled_table] shortcode so that I can assign the table the correct width.

Does anyone know how I can do this?

221 posts
  • 4 Years of Membership
  • United Kingdom
  • Author Level 3
  • Collector Level 2
+2 more
NuclearThemes
says

Could you use an increment in the styled_columns function and then get it at the end with /style_table?

I’m only just coming across shortcodes so I’m not too sure whether that would work but it’s a thought.

407 posts
  • Top Monthly Author
  • Weekly Top Seller
  • Elite Author
  • Author Level 9
+7 more
EugeneO
says

I managed to get it to work using this:

$columns = substr_count( $content, '[styled_column' );

Note the front bracket “[” in the string it searches for so it distinguishes between [styled_column] and [/styled-column].

3535 posts
  • Power Elite Author
  • Author Level 12
  • Trendsetter
  • United States
+13 more
sevenspark
Moderator
says

Another way is to use Regular Expressions (I’ve done this for normal columns).

by
by
by
by
by
by