Fix for invalid table structure
-
The table shortcode was not creating an opening tr tag properly. The follow code fixes the issue.
if( !function_exists('tboot_table_shortcode') ) { function tboot_table_shortcode( $atts ) { extract( shortcode_atts( array( 'cols' => 'none', 'data' => 'none', 'strip' => '', 'style' => '', 'border' => '', 'condense' => '', 'hover' => '', ), $atts ) ); $strip = ($strip == 'yes') ? 'table-striped' : ''; $border = ($border == 'yes') ? 'table-bordered' : ''; $condense = ($condense == 'yes') ? 'table-condensed' : ''; $hover = ($hover == 'yes') ? 'table-hover' : ''; $cols = explode(',',$cols); $data = explode(',',$data); $total = count($cols); $total_data = count($data); $output = '<table class="table ' . $strip . ' ' . $border . ' ' . $condense . ' ' . $hover . '"><tr>'; foreach($cols as $col): $output .= '<th>'. $col . '</th>'; endforeach; $output .= '</tr><tr>'; $counter = 1; foreach($data as $datum): $output .= '<td>'. $datum .'</td>'; if($counter%$total==0): $output .= '</tr>'; if($counter < $total_data): $output .= '<tr>'; endif; endif; $counter++; endforeach; $output .= '</table>'; return $output; } add_shortcode( 'tboot_table', 'tboot_table_shortcode' ); }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Fix for invalid table structure’ is closed to new replies.