Last active
September 15, 2021 17:04
-
-
Save jmarreros/750ee1aacbe7344a09c790ae92e859ac 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
<?php //obviar este línea | |
add_filter( 'the_content', 'dcms_list_data' ); | |
function dcms_list_data( $content ) { | |
$slug_page = 'frutas'; //slug de la página en donde se mostrará la tabla | |
$table_name = 'data_fruit'; // nombre de la tabla | |
if (is_page($slug_page)){ | |
global $wpdb; | |
$items = $wpdb->get_results("SELECT * FROM `$table_name`"); | |
$result = ''; | |
// nombre de los campos de la tabla | |
foreach ($items as $item) { | |
$result .= '<tr> | |
<td>'.$item->fruit_id.'</td> | |
<td>'.$item->name.'</td> | |
<td>'.$item->variety.'</td> | |
</tr>'; | |
} | |
$template = '<table class="table-data"> | |
<tr> | |
<th>ID</th> | |
<th>Nombre</th> | |
<th>Variedad</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