【问题标题】:shortcode content is showed twice or at the bottom of the page短代码内容显示两次或在页面底部
【发布时间】:2017-05-17 16:08:11
【问题描述】:

我的简码有问题,它应该出现在帖子 div 中,但它显示在页面内容的末尾(页面底部)。 这是代码:

add_shortcode('registru', "show_registru");

function show_registru()
{
    global $wpdb;

    $list_inregistrari = $wpdb->get_results('SELECT * FROM ' . $wpdb->prefix . 'wprc_ong_casa ORDER BY data_inregistrare ASC');
    $sold_init = $wpdb->get_var('SELECT valoare FROM ' . $wpdb->prefix . 'wprc_solduri LIMIT 1');

    ob_start();
    print_table($list_inregistrari, $sold_init);
    return ob_get_clean();
}

如果我尝试使用 ob_get_content() 而不是 ob_get_clean(),表格将在帖子 div 中显示两次,在页面底部显示一次.

我也试过这样做(它仍然在页面底部):

ob_start();
print_table($list_inregistrari, $sold_init);
$return = ob_get_contents();
ob_clean();
return $return;

*print_table 函数只是回显了一些 HTML 代码,所以我也尝试将所有带有 HTML 代码的字符串放入一个变量中,然后返回它,但仍然没有。

【问题讨论】:

  • 欢迎您!请考虑将代码示例减少为重现问题所必需的项目。这将有助于确定此处的问题。
  • 我还没有发现任何问题。您是否尝试过打开 WP_DEBUG 运行以查看是否有任何错误? codex.wordpress.org/Debugging_in_WordPress
  • 我用的是WP_DEBUG,没有报错

标签: php wordpress shortcode


【解决方案1】:

知道了!所以问题是print_table 中的元素缺少结尾</table> 标记。

为你的函数试试这个(注意倒数第二行):

        </tr>
    <?php

        endforeach;

        front_table_footer($total_incasari, $total_plati, $sold_init);

        echo '</table>'; // needs a closing tag
}

【讨论】:

  • 非常感谢!这就是问题所在:))
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-06-02
  • 1970-01-01
  • 1970-01-01
  • 2018-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多