【发布时间】:2014-12-16 14:49:39
【问题描述】:
我有以下 WordPress 短代码功能:
function wp_shortcode() {
static $i=1;
$return = '['.$i.']';
$i++;
return $return;
}
add_shortcode('shortcode', 'wp_shortcode');
这很好用。每次在文章中调用函数时,$i 变量都会递增。所以对于
[shortcode][shortcode][shortcode][shortcode]
输出符合预期
[1][2][3][4]
但是
如果文章有多个页面,则计数器会在下一个文章页面上重置。所以对于:
[shortcode][shortcode][shortcode][shortcode]
<!--nextpage-->
[shortcode][shortcode][shortcode][shortcode]
输出是
[1][2][3][4]
<!--nextpage-->
[1][2][3][4]
而不是想要的输出:
[1][2][3][4]
<!--nextpage-->
[5][6][7][8]
无论如何要改变这个?
【问题讨论】: