Bootstrap表仅在用户登录时显示

时间:2018-01-02 15:24:28

标签: wordpress bootstrap-table

我在我的一个WordPress CMS页面上使用Bootstrap Table extension。当我登录到WordPress后端并访问该页面时,表格显示就好了。但是,如果我退出并访问同一页面,则只显示表格标题,但不再设置样式,也不显示任何数据。以下是我的实施:

包含JSON文件网址的页面中的代码用于获取数据:

<table data-pagination="true" data-search="true" data-toggle="table" data-url="https://example.com/assets/maps/data/out/file.json">
    <thead>
        <tr>
            <th data-sortable="true" data-field="first_name">First Name</th>
            <th data-sortable="true" data-field="last_name">Last Name</th>
            <th data-sortable="true" data-field="org_name">Organization</th>
            <th data-sortable="true" data-field="state">State</th>
            <th data-sortable="true" data-field="country">Country</th>
            <th data-sortable="true" data-field="cert_type">Certification Type</th>
        </tr>
    </thead>
</table> 

以下是添加到头文件中以包含扩展文件的内容:

<?php if ($post->ID == 1174) { ?>                   
    <script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
    <link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="https://example.com/assets/bootstrap-table/bootstrap-table.css">
    <script type="text/javascript" src="https://example.com/assets/bootstrap-table/bootstrap-table.js"></script>
<?php } ?>

我确保jQuery等没有冲突,只加载一次。我真的不确定问题是什么。我也没有在控制台中看到任何问题。

2 个答案:

答案 0 :(得分:0)

在WordPress中进行了额外的故障排除之后,我得出结论,X主题及其Cornerstone编辑器就是问题所在。为了解决这个问题,我将表格HTML从页面中取出并将其转换为functions.php文件中的函数。以下是详细信息:

将表格代码作为函数移动到functions.php

function c_table() {
    return '<table data-pagination="true" data-search="true" data-toggle="table" data-url="https://example.com/assets/maps/data/out/file.json">'
            .'<thead>'
                .'<tr>'
                    .'<th data-sortable="true" data-field="first_name">First Name</th>'
                    .'<th data-sortable="true" data-field="last_name">Last Name</th>'
                    .'<th data-sortable="true" data-field="org_name">Organization</th>'
                    .'<th data-sortable="true" data-field="state">State</th>'
                    .'<th data-sortable="true" data-field="country">Country</th>'
                    .'<th data-sortable="true" data-field="cert_type">Certification Type</th>'
                .'</tr>'
            .'</thead>'
        .'</table>';
    }
add_shortcode('custom_script_c_table', 'c_table');

使用短代码

创建功能后,我使用以下短代码更新了我的页面:

[custom_script_c_table]

答案 1 :(得分:-1)

在MYJSON.com上保存您的数据子集 - 这会模拟您知道可行的链接。  使用myjson.com的链接替换json的url。您还可以直接在浏览器中检查网址(“https://example.com/assets/maps/data/out/file.json”),而无需运行您的网页。这会将数据问题与可能的权限问题隔离开来。