如何将一部分短代码收集为数组

时间:2014-07-21 23:17:30

标签: php wordpress getelementsbyname

我在wordpress中有一个简短的代码,看起来像这样

[wp_charts title="linechart" type="line" align="alignleft" margin="5px 20px" datasets="20,25,10,10,10,10,10,105,59,34,23,21,54,12,22,34,54,21,22,12,3,4,7,8,4,6,2,9" labels="25th,26th,27th,28th,29th,30th,31st,1st,2nd,3rd,4th,5th,6th,7th,8th,9th,10th,11th,12th,13th,14th,15th,16th,17th,18th,19th,20th,21st,22nd,23rd,24th" scaleoverride="true" scalesteps="8" scalestepwidth="10" scalestartvalue="0" scaleFontSize="16" canvaswidth="920px" canvasheight="460px" relativewidth="2" width="920px" height="460px" backgroundcolor="#000"]

我需要收集“数据集”作为数组然后添加它们并回显总数但我不确定如何。我知道如何通过id获取元素但不知道如何获得短代码的那部分..任何帮助将不胜感激

作为旁注,我在word word中使用phpexec从帖子中运行php,所以如果有一个使用php的方法,那将是最好的。

更新 $ array是我需要填充数据集的东西

    <p style="text-align: center;"><strong><span style="font-size: 14pt;">MILES WALKED BY DAY<br>
        TOTAL MILES SO FAR
        <?php

        $array = array(**this is the area i need to populate with datasets**); 
        $mystr = array_sum($array); 
        echo $mystr; 
        ?>
        </span>
        </strong>
        </p>
        [wp_charts title="linechart" id="chart" type="line" align="alignleft" margin="5px 20px" 
datasets="20,25,10,10,10,10,10,22,59,34,23,21,54,12,22,34,54,21,22,12,3,4,7,8,4,6,2,9" 
    labels="25th,26th,27th,28th,29th,30th,31st,1st,2nd,3rd,4th,5th,6th,7th,8th,9th,10th,11th,
    12th,13th,14th,15th,16th,17th,18th,19th,20th,21st,22nd,23rd,24th" sumdatasets='' 
    scaleoverride="true" scalesteps="10" scalestepwidth="5" scalestartvalue="0" 
    scaleFontSize="16" canvaswidth="920px" canvasheight="460px" relativewidth="2" 
    width="920px" height="460px" backgroundcolor="#000"]

1 个答案:

答案 0 :(得分:0)

不确定您是否自己注册了该短代码,但在这种情况下:

add_shortcode('wp_charts', 'wp_charts_shortcode');

function wp_charts_shortcode($atts) {
    if(isset($atts['datasets'])) {
        return array_sum(explode(',', $atts['datasets']));
    }
}