【问题标题】:Shortcode won't render in correct place简码不会在正确的位置呈现
【发布时间】:2023-03-29 06:25:02
【问题描述】:

我试图在主要内容正文之前输出我的简码内容,我根本无法让它工作,也找不到答案。

如果我使用简单的字符串或数字,它会在正确的位置输出,但是当我尝试输出表格 html 时,它会呈现在内容下方。

编辑:我刚刚检查了源代码 - 代码以正确的顺序呈现,但显示方式不同。我真的很困惑。

我的代码如下:

/* SHORTCODES */


        //inject code on initialization
        add_action('init', 'ebs_register_shortcodes');

        //register shortcodes
        function ebs_register_shortcodes() {
        add_shortcode('offer_table', 'ebs_table_shortcode');
        }

        function ebs_table_shortcode() {

        $page_offers = get_post_meta( get_the_ID(), 'offers_on_page', true);
        $rank = 1;

        //Table Content
        $table = '<table>
        <thead>
        <tr>
        <th>Rank</th>
        <th>Brands</th>
        <th>User Rating</th>
        <th>Signup Bonus</th>
        <th>Key Features</th>
        <th>Play Now</th>
        </tr>
        </thead>
        <tbody>
        <tr>';

        foreach ($page_offers as $index => $page_id) {

        $table .= '<td>'.$rank.'</td>';
        $table .= '<td>'.get_field('ebs_brand_logo', $page_id).'</td>';

        if ( get_field('ebs_launch_date' !== '') ) { 
        $table .= '<td>'.get_field('ebs_launch_date', $page_id).'</td>';
        }

        $table .= '<td>'.get_field('ebs_rating', $page_id).'</td>';
        //echo '<td>'.get_field('ebs_review_link', $page_id).'</td>';
        $table .= '<td>'.get_field('ebs_signup_bonus', $page_id).'</td>';
        $table .= '<td>'.get_field('ebs_key_features', $page_id).'</td>';
        $table .= '<td>'.get_field('ebs_clean_link', $page_id).'</td>';
        //$table .= '<td>'.get_field('ebs_brand_name', $page_id).'</td>';

        $table .= '</tr>';
        $rank++;

        }

        $table .= '</tbody><br>';

        //return the table
        return $table;

        }

提前感谢您的帮助!

【问题讨论】:

  • 你应该在一开始就在 foreach 中启动&lt;tr&gt;,现在你只做一次......
  • 已修复,感谢您的捕获!还是不行。

标签: php wordpress shortcode


【解决方案1】:

解决了!

问题是缺少标签。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-06
    • 1970-01-01
    • 2012-08-21
    相关资源
    最近更新 更多