[ad_1]
Hi,
thanks for your post, and sorry for the trouble.
Where are you seeing this wrong counting behavior? Wherever I check, e.g. on https://tablepress.org/demo/ which is table with a header and footer, the count of 10 rows and 200 entries is correct (the table has 202 rows on the “Edit” screen)?
Regards,
Tobias
Thread Starter
plaicy
(@plaicy)
Sorry for the message. I think found the problem: I had an off-by-one error in my pluging (-1 in for initialization was missing). Just for info I use this code as plugin:
<?php
/* [...] */
// see
if (!defined('WPINC')) {
die;
}
add_filter(
'tablepress_shortcode_table_default_shortcode_atts',
'bbgid_table_shortcode_atts', 10, 1);
add_filter('tablepress_table_render_data', 'bbgid_table_render_data', 10, 4);
function bbgid_table_shortcode_atts($default_atts) {
$default_atts['bbgid_columns'] = '';
return $default_atts;
}
function bbgid_table_render_data($table, $orig_table, $render_options) {
if (!isset($render_options['bbgid_columns'])) {
return $table;
}
$columns_raw = preg_split("/,/", $render_options['bbgid_columns']);
$columns = [];
foreach ($columns_raw as $column_raw) {
$column = intval($column_raw);
if ($column > 0) {
array_push($columns, $column - 1);
}
}
$num_rows = count($table['data'] );
$num_columns = ($num_rows > 0 ) ? count($table['data'][0]) : 0;
for ($col_idx = $num_columns - 1; $col_idx >= 0; $col_idx--) {
if (!in_array($col_idx, $columns)) {
continue;
}
for ($row_idx = $num_rows - 1; $row_idx >= 0; $row_idx--) {
$cell_content = $table['data'][ $row_idx][$col_idx];
if (preg_match('/^\s*([0-9]+)\s*$/', $cell_content, $matches)) {
$cell_content = "<a href=\"https://www.boardgamegeek.com/boardgame/{$matches[1]}/\">{$cell_content}</a>";
}
$table['data'][$row_idx][$col_idx] = $cell_content;
}
}
return $table;
}Usage for example:[table id=2 bbgid_columns="2" /]
PS: I once have to exend it to support multiple ids in one cell (semicolon seperated). Will not be complicated but had not time yet.
