Created
January 21, 2021 14:32
-
-
Save jmarreros/78dc31ac71aa382f1a3568a8ec34b6c4 to your computer and use it in GitHub Desktop.
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
<? // no copiar esta línea | |
add_filter( 'the_content', 'dcms_list_data' ); | |
function dcms_list_data( $content ) { | |
$database_name = 'employees'; // nombre de la base de datos | |
$database_user = 'root'; | |
$database_pass = 'root'; | |
$database_server = 'localhost'; | |
$table_name = 'tbl_employees'; // nombre de la tabla | |
$slug_page = 'empleados'; //slug de la página en donde se mostrará la tabla | |
if (is_page($slug_page)){ | |
$mydb = new wpdb($database_user, $database_pass, $database_name, $database_server); | |
$items = $mydb->get_results("SELECT * FROM `$table_name`"); | |
// nombre de los campos de la tabla | |
foreach ($items as $item) { | |
$result .= '<tr> | |
<td>'.$item->emp_no.'</td> | |
<td>'.$item->first_name.'</td> | |
<td>'.$item->birth_date.'</td> | |
</tr>'; | |
} | |
$template = '<table class="table-data"> | |
<tr> | |
<th>ID</th> | |
<th>Nombre</th> | |
<th>Fecha</th> | |
</tr> | |
{data} | |
</table>'; | |
return $content.str_replace('{data}', $result, $template); | |
} | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment