首页 > 解决方案 > 用一系列序列号替换短代码中的内容

问题描述

我需要用一系列序列号替换我的简码中的内容(因此,无论我在两个这样的简码标签之间放置一些内容,它都需要用一个按顺序排列的数字替换它。)

这是我尝试使用的代码,

function ref_shortcode( $atts , $content = null ) {
    ob_start();
    for ($x = 0; $x <= 10; $x++) {
        $numbers = $x;
        echo '<a>' . $numbers . '</a>';
    return ob_get_clean();
    }   
}
add_shortcode( 'ref', 'ref_shortcode' );

代码的问题是它用 0 替换了每个短代码。代码中是否有错误?我不希望它按顺序排列(0,1,2,3,4,5......)

标签: phpwordpressshortcode

解决方案


推荐阅读