首页 文章

Wordpress - 循环问题内部的短代码 - IE,Chrome,Safari

提问于
浏览
0

$ loop = new WP_Query(array('post_type'=>'special_offers',>'posts_per_page'=> -1)); while($ loop-> have_posts()):$ loop-> the_post(); echo do_shortcode('[my_special_offer_item]'); ENDWHILE; wp_reset_query();`

我的短代码在IE,Chrome和Safari的while循环中没有递增,因此它们都是重复的...但在FF内部它完美无缺 .

1 回答

  • 1

    很抱歉怀疑你,但我确实很难相信 do_shortcode 基于浏览器的工作方式不同 . 由于这是PHP代码,它在到达浏览器之前执行,虽然PHP代码实际上可能会根据用户代理执行不同的操作,但实际情况并非如此 .

    但是,如果短代码本身存在任何渲染问题,您可能会在浏览器中看到不同的东西,但这更接近模板/主题本身而不是代码 .

    至于do_shortcode,请注意Codex文档(https://codex.wordpress.org/Function_Reference/do_shortcode)和源代码(https://core.trac.wordpress.org/browser/tags/4.2.2/src/wp-includes/shortcodes.php#L189)似乎都是以任何方式自动递增 .

    也许你're supposed to inject a dynamic variable into it to make different shortcode searches depending on the post? If so, check for variable string interpolation or just concatenation Here'是一个例子(https://wordpress.org/support/topic/how-to-use-echo-do_shortcode-with-dynamic-variable

    <?php echo do_shortcode('[walkscore ws_wsid="example" ws_address="'.get_post_meta($post->ID, 'pyre_full_address', true).'"]'); ?>
    

    我希望这有帮助 .

相关问题