说到这个WordPress插入表格是很多人需求,但是一直没有几个人来做这样的教程,当然部分人采用其它的一些手段来实现WordPress插入表格,今天教大家使用WordPress插入表格短代码来实现表格功能,WordPress插入表格短代码使用非常的简单只需要当前在主题的functions文件中加入以下WordPress插入表格短代码即可。
add_shortcode( 'table', 'ruikeedu_table_shortcode_handler' );
function ruikeedu_table_shortcode_handler( $atts, $content='' ) {
extract( shortcode_atts( array(
'border' => '1',
'cellpading' => '0',
'cellspacing' => '0',
'width' => ''
), $atts ) );
$output = '';
$trs = explode("\r\n\r\n", $content);
foreach($trs as $tr){
$tr = trim($tr);
if($tr){
$tds = explode("\r\n", $tr);
$output .= '<tr>';
foreach($tds as $td){
$td = trim($td);
if($td){
$output .= '<td>'.$td.'</td>';
}
}
$output .= '</tr>';
}
}
if($class){
$class = ' class="'.$class.'"';
}
if($width){
$width = ' width="'.$width.'"';
}
$output = '<table border="'.$border.'" cellpading="'.$cellpading.'" cellspacing="'.$cellspacing.'" '.$width.' '.$class.' >'.$output.'</table>';
return $output;
}
简码使用
[table width="95%"]
位置
大小
价格
出现的页面
顶部广告位
728X80 静态图片
1000 RMB 一个月
整站所有页面
侧边栏广告位
300X150 静态图片
500 RMB 一个月
整站所有页面,最多三个
[/table]
WordPress插入表格教程介绍完毕,WordPress插入表格简单吧瑞课学院还有很多关于WordPress教程呢,如果您想更个性化完善您的主题模板可以多看看瑞课教程。

