374 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 3-4 years
  • United Kingdom
  • Referred between 100 and 199 users
  • Bought between 1 and 9 items
  • Exclusive Author
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?

215 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 1 and 9 users
  • Sold between 100 and 1 000 dollars
  • United Kingdom
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.

374 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 3-4 years
  • United Kingdom
  • Referred between 100 and 199 users
  • Bought between 1 and 9 items
  • Exclusive Author
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].

3365 posts
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Community Moderator
  • Bought between 50 and 99 items
  • Referred more than 2000 users
  • Has been a member for 4-5 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
+4 more
sevenspark Volunteer moderator says

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

by
by
by
by
by
by