【问题标题】:Wordpress Not Displaying Tables Correctly?Wordpress 不能正确显示表格?
【发布时间】:2011-11-01 06:07:03
【问题描述】:

我正在使用 Wordpress 中的帖子模板来创建表格。不过格式有点乱。

生成代码的 PHP 进入并查询服务器以获取用户当天的测试信息。然后它会缩减该内部报告以仅获取表格。请注意,报告不会关闭 </tbody> 标签,因此我不得不使用 str_replace 来关闭该标签。

global $current_user;

get_currentuserinfo();

$raw_contents = file_get_contents('http://******/NamedRptRun.asp?Rpt=DailyUserSum&Prj=******_****UserId='.($current_user->user_login));

    $trim_raw = trim($raw_contents);
//echo htmlentities($trim_raw);

if ($trim_raw == 'No Records Returned')  {

    echo 'No test cases to report today.';

} else {

    $tag = '<TABLE';

    $topTrim_contents = stristr($raw_contents, $tag);

    $tag = '</BODY>';

    $table_only = stristr($topTrim_contents, $tag, TRUE);

    $table_only = str_replace("</tr></table>", "</tbody></tr></table>",$table_only);

   echo htmlentities($table_only);
   echo str_replace(array("\r\n","\n","\t"), ' ',$table_only);

}

这为我提供了表格的代码(仅用于调试目的),以及表格的内容。但是,表格的值实际上并不在表格内,而是显示在表格上方的行中。

<TABLE cellspacing=0 cellpadding=0 border=1 bordercolor=Silver>
<thead class=b>
<TR bgColor=WHITE>
<th>&nbsp;Engineer&nbsp;</th><th>&nbsp;Passed&nbsp;</th><th>&nbsp;PWWarn&nbsp;</th><th>&nbsp;Blocked&nbsp;</th><th>&nbsp;Failed&nbsp;</th><th>&nbsp;Total Run&nbsp;</th></tr></thead><tbody class=h><TR bgColor=#F1F1F1><TD nowrap>myname</td><TD nowrap>1</td><TD nowrap>0</td><TD nowrap>0</td><TD >0</td><TD nowrap>1</td></tbody></tr></table>

10001
 Engineer    Passed      PWWarn      Blocked     Failed      Total Run 
myname

有人对为什么会发生这种情况有任何建议吗?

正在粘贴生成的最终表格的视图页面源。

<table border="1" cellspacing="0" cellpadding="0">
    <thead class="b">
        <tr bgcolor="WHITE">
            <th> Engineer</th>
            <th> Passed</th>
            <th> PWWarn</th>
            <th> Blocked</th>
            <th> Failed</th>
            <th> Total Run</th>
        </tr>
    </thead>
    <tbody class="h">
        <tr bgcolor="#F1F1F1">
            <td nowrap="nowrap">myname</td>
        </tr>
    </tbody>
</table>

【问题讨论】:

  • 对于初学者来说,你的结束 &lt;/tbody&gt;&lt;/tr&gt; 标签是错误的。另外,你用的是什么浏览器?可能会帮助我重现问题...
  • 我使用的是最新版本的 Firefox 和 Chrome。我也在运行 Wordpress 3.2.1,有趣的是,它在 3.1 中运行良好。
  • 好吧,你的 HTML——甚至是你的原始版本;我刚刚把它粘贴到了——在 WordPress 3.2.1 的帖子中对我来说效果还不错。也许您的主题 CSS 或插件或其他东西正在破坏?
  • 是的,我也试过了,我将检查并禁用所有不必要的东西。可以是 SimplePostTemplate 或 Exec-PHP 插件吗?从结果服务器到帖子的过程依赖于这两个插件。
  • 生成后的实际呈现的 HTML 是什么样的?如,使用“视图->页面源”?这将消除很多可能导致问题的因素。

标签: php wordpress html-table


【解决方案1】:

联系 SimplePostTemplate 的作者后找到了解决方案。似乎 wordpress 会过滤掉坏的 HTML,这正是它对我的表格所做的,因此它没有正确显示。

我能够要求其他部门在 html 进入 wordpress 之前对其进行清理,从而通过过滤器并解决问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多