【发布时间】:2017-06-20 01:32:03
【问题描述】:
我在functions.php 文件上创建了一个函数,该函数从我们数据库中的表中检索数据并将其放在HTML 中。
我的问题是我需要设置这个表格的样式,它的列和行以设置边距、填充等。
这是我目前所拥有的:
add_shortcode( 'persona-table', 'persona_table_shortcode' );
// this function generates the shortcode output
function persona_table_shortcode( $args ) {
global $wpdb;
// Shortcodes RETURN content, so store in a variable to return
$content = '<table class="tabledatos">';
$content .= '<tr><th>Firstname</th><th>Lastname</th><th>Points</th></tr>';
$results = $wpdb->get_results( 'SELECT * FROM persona' );
foreach ( $results AS $row ) {
$content = '<tr>';
// Modify these to match the database structure
$content .= '<td class=rowtable>' . $row->ID_per . '</td>';
$content .= '<td class=rowtable>' . $row->nombre . '</td>';
$content .= '<td class=rowtable>' . $row->apellido . '</td>';
$content .= '<td class=rowtable>' . $row->documento . '</td>';
$content .= '<td class=rowtable>' . $row->tel. '</td>';
$content .= '<tr>';
}
$content .= '</table>';
// return the table
return $content;
}
正如您在每个<td> 上看到的那样,我添加了一个名为:rowtable 的类,但是当我刷新页面时,表格不会采用该类上定义的样式。另外,我尝试使用引号,正如您在整个表的 tabledatos 类中看到的那样,但这不起作用。
如何向此代码添加类,以便在 style.css 文件中自定义它们?
在此致谢
【问题讨论】:
-
你确定你有
rowtable类吗?开发者控制台中有任何线索吗?
标签: php html css mysql wordpress