Last active
January 3, 2016 07:28
-
-
Save coreyweb/8429247 to your computer and use it in GitHub Desktop.
WordPress Table Shortcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// this shortcode allows you to add multiple rows and columns in a table | |
// corey modified from this from a shortcode found here: | |
// http://wpsnipp.com/index.php/functions-php/shortcode-tables-with-multiple-rows-and-columns/ | |
// example shortcode: | |
// [specs cols="2" data="Row1 Item1:|Row1 Item2|Row2 Item1:|Row2 Item2"] | |
// (define # of columns in 'cols' and place your contents in 'data' with a delimiter) | |
// markup is Bootstrap | |
function specs_list( $atts ) { | |
extract( shortcode_atts( array( | |
'cols' => 'none', | |
'data' => 'none', | |
), $atts ) ); | |
$data = explode('|',$data); | |
$total = $cols; | |
$output .= '<table class="table table-striped table-bordered table-condensed table-specs"><tbody><tr>'; | |
$counter = 1; | |
foreach($data as $datum): | |
$span= '3'; | |
if($counter%$total==0): | |
$span = '6'; | |
endif; | |
$output .= '<td class="span'. $span .'">'.$datum.'</td>'; | |
if($counter%$total==0): | |
$output .= '</tr>'; | |
endif; | |
$counter++; | |
endforeach; | |
$output .= '</tbody></table>'; | |
return $output; | |
} | |
add_shortcode( 'specs', 'specs_list' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment