dongtao5104 2014-07-21 23:17
浏览 23

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

I have a short code in wordpress that looks like this

[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"]

and i need to collect the "datasets" as an array then add them and echo the total number but im not sure how. I know how to get an element by id but not how to get just that part of the short code.. any help would be appreciated

As a side note im using phpexec in word press to run php from within a post so if there is a method using php it would be best.

Update the $array is the thing that i need to populate with datasets

    <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条回答 默认 最新

  • douyou3619 2014-07-22 00:41
    关注

    Not sure if you're registering that shortcode yourself, but in that case:

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

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改