?php //don’t copy this line

// Show custom table data in a WordPress specific page
// includes pagination and search

add_filter( ‘the_content’, ‘dcms_list_data’ );

function dcms_list_data( $content ) {
$slug_page = ‘aycon_learningcertif’; //slug page where show data
$table_name = ‘tabla_ppal’; // custom table name
$items_per_page = 10; // quantity per page

if ( is_page($slug_page) ){
global $wpdb;

$search_condition = »;
$search = $_REQUEST[‘search’]??»;
if ( $search ) $search_condition = «WHERE `first_name` like ‘%$search%'»;

$start_number = $_REQUEST[‘start’]??0;
if ( $start_number < 0 || ! is_numeric( $start_number ) ) $start_number = 0; // Count items $sql = "SELECT COUNT(*) FROM `$table_name` $search_condition"; $count = $wpdb->get_var($sql);

// Items
$sql = «SELECT * FROM `$table_name` $search_condition LIMIT $start_number, $items_per_page»;
$items = $wpdb->get_results($sql);

$content .= dcms_print_search($search);
$content .= dcms_print_table($items);
$content .= dcms_print_pagination($start_number, $items_per_page, $count, $search);
}

return $content;
}

function dcms_print_search($search){
return ‘



‘;
}

function dcms_print_table($items){
$result = »;

// field names
foreach ($items as $item) {
$result .= ‘

‘.$item->id.’ ‘.$item->first_name.’ ‘.$item->last_name.’ ‘.$item->email.’ ‘.$item->birthdate.’

‘;
}

$template = ‘

{data}

ID Nombre Apellido Correo Cumpleaños

‘;

return str_replace(‘{data}’, $result, $template);
}

function dcms_print_pagination($start_number, $items_per_page, $count, $search){
$navbar = »;

if ( $count > $items_per_page ){
$nav_count = 0;
$page_count = 1;
$str_search = »;
$current_page = $start_number/$items_per_page + 1;

if ( $search ) $str_search = «&search=$search»;

while ( $nav_count < $count ) { if ( $page_count === $current_page ){ $navbar .= "{$page_count} «;
} else {
$navbar .= «{$page_count} «;
}
$nav_count += $items_per_page;
$page_count++;
}

$navbar = «

$navbar

«;
}

return $navbar;
}