..えっ?なにそれ。こわい。..
仕事がらみで、Wordpressのプラグインをちょこっと改造したのでメモ。
WordPressでテーブル(表)を扱うツールって、表を別で管理したりとちょっと大げさなのがおおくていまいちしっくりくるのがなかったので、Light Formatterというのをつかってたんだけど、colspanとかが使えなくて…使えないのはHPの説明不足もあるんだろう(要するに自分が機能をよく調べてないから使えない)って思ってて、とりあえず改行をいれてテーブルを分割するカタチで見た目は思い通りになってるからいいや…って思って使ってたんだけど、今回は仕事上どうしても必要なので、プログラムの中身を読んでみた…そしたら、colspanとかはどうも機能的に用意されてないことが判明…なので、追加してみた。
190行目あたりの
if ($flg_header) {<br />
// print th tag<br />
$ret .= $this->_add_attr('th', array('id' => $local_options['id']<br />
, 'style' => join(';', array_filter(array($local_options['style'], $local_options['th_style'])))<br />
, 'class' => join(';', array_filter(array($local_options['class'], $local_options['th_class'])))<br />
));<br />
$ret .= "$col</th>\n";<br />
} else {<br />
// print td tag<br />
$ret .= $this->_add_attr('td', array('id' => $local_options['id']<br />
, 'style' => join(';', array_filter(array($local_options['style'], $local_options['td_style'])))<br />
, 'class' => join(';', array_filter(array($local_options['class'], $local_options['td_class'])))<br />
));<br />
$ret .= "$col</td>\n";<br />
// print th tag<br />
$ret .= $this->_add_attr('th', array('id' => $local_options['id']<br />
, 'style' => join(';', array_filter(array($local_options['style'], $local_options['th_style'])))<br />
, 'class' => join(';', array_filter(array($local_options['class'], $local_options['th_class'])))<br />
));<br />
$ret .= "$col</th>\n";<br />
} else {<br />
// print td tag<br />
$ret .= $this->_add_attr('td', array('id' => $local_options['id']<br />
, 'style' => join(';', array_filter(array($local_options['style'], $local_options['td_style'])))<br />
, 'class' => join(';', array_filter(array($local_options['class'], $local_options['td_class'])))<br />
));<br />
$ret .= "$col</td>\n";<br />
を
<br />
if ($flg_header) {<br />
// print th tag<br />
$ret .= $this->_add_attr('th', array('id' => $local_options['id']<br />
, 'style' => join(';', array_filter(array($local_options['style'], $local_options['th_style'])))<br />
, 'class' => join(';', array_filter(array($local_options['class'], $local_options['th_class'])))<br />
<strong> , 'colspan' => $local_options['colspan']<br />
, 'rowspan' => $local_options['rowspan']<br />
, 'width' => $local_options['width']</strong><br />
));<br />
$ret .= "$col</th>\n";<br />
} else {<br />
// print td tag<br />
$ret .= $this->_add_attr('td', array('id' => $local_options['id']<br />
, 'style' => join(';', array_filter(array($local_options['style'], $local_options['td_style'])))<br />
, 'class' => join(';', array_filter(array($local_options['class'], $local_options['td_class'])))<br />
<strong> , 'colspan' => $local_options['colspan']<br />
, 'rowspan' => $local_options['rowspan']<br />
, 'width' => $local_options['width']</strong><br />
));<br />
$ret .= "$col</td>\n";<br />
if ($flg_header) {<br />
// print th tag<br />
$ret .= $this->_add_attr('th', array('id' => $local_options['id']<br />
, 'style' => join(';', array_filter(array($local_options['style'], $local_options['th_style'])))<br />
, 'class' => join(';', array_filter(array($local_options['class'], $local_options['th_class'])))<br />
<strong> , 'colspan' => $local_options['colspan']<br />
, 'rowspan' => $local_options['rowspan']<br />
, 'width' => $local_options['width']</strong><br />
));<br />
$ret .= "$col</th>\n";<br />
} else {<br />
// print td tag<br />
$ret .= $this->_add_attr('td', array('id' => $local_options['id']<br />
, 'style' => join(';', array_filter(array($local_options['style'], $local_options['td_style'])))<br />
, 'class' => join(';', array_filter(array($local_options['class'], $local_options['td_class'])))<br />
<strong> , 'colspan' => $local_options['colspan']<br />
, 'rowspan' => $local_options['rowspan']<br />
, 'width' => $local_options['width']</strong><br />
));<br />
$ret .= "$col</td>\n";<br />
に変更したら、無事動作してる模様。にしてもなんでこのcolspanがなかったんだろう。邪道なんだっけ?この属性…。あと、widtnも追加(もしかしたらこれも邪道かも)でもstyleで指定するより楽なんでこれ使ってんだ…いつも。
これで、投稿フォーム内で、
¦~AAA¦~BBB¦~CCC¦<br />
¦ABC¦03-3333-3333¦##rowspan=2##DDDD¦<br />
¦DEF¦03-4444-4444¦<br />
¦ABC¦03-3333-3333¦##rowspan=2##DDDD¦<br />
¦DEF¦03-4444-4444¦<br />
とすると、以下のような表に…。
|~AAA|~BBB|~CCC|
|ABC|03-3333-3333|##rowspan=2##DDDD|
|DEF|03-4444-4444|
楽ちん。担当サイト全部置き換えないとなぁ…。
ちなみにCSSへの追加は以下の通り…
.lftable {width: 100%;border: 0px solid #333; border-collapse: collapse; margin: 1em 0 1em 0;}<br />
.lftable th {border-bottom: 1px solid #333; border-top: 1px solid #333; background-color:#CEC;padding: 5px;}<br />
.lftable td {border-bottom: 1px solid #CCC; padding: 5px;}<br />
.lftable td.bdno {border-bottom: 0px solid #333; }<br />
.lftable th {border-bottom: 1px solid #333; border-top: 1px solid #333; background-color:#CEC;padding: 5px;}<br />
.lftable td {border-bottom: 1px solid #CCC; padding: 5px;}<br />
.lftable td.bdno {border-bottom: 0px solid #333; }<br />
メモメモ。
No related posts.





