duanpang1987 2019-04-27 05:26
浏览 622

返回for循环for循环的结果

Well I gave up on trying to get a field from formiddable forms in a current "all" view, in that case I had a field (that contained SCALE01, SCALE02 etc) that would have done the trick but I have no user in the form to hook it on to. And I eventually gave up.

So here I have something that works, the echo is spitting out the answer four times each (there are four entries from fomiddable displaying)like so:

<a href="file1">file1<a>
<a href="file2">file2<a>
<a href="file3">file3<a>
<a href="file4">file4<a>

(repeated 4 times)

The file links are correct though!

I need to turn that echo into a return so where I put the shortcode from the wordpress function the return gives me the first then the second then the third etc in the right place not at the top of the page. And not four times, just once :)

function scale_verification_certificate_func($atts) {
    $current_user = wp_get_current_user();
    $ffield = FrmProEntriesController::get_field_value_shortcode(array(
            'field_id' => 140, 
            'user_id' => 'current'));

    for ($i = 1; $i <= 10; $i++) {        
        foreach (glob("./clients/Sites/" . $ffield . "/SCALE0". $i . "/*SCALE_VERIFICATION_CERTIFICATE*", GLOB_NOSORT) as $filename) {
            echo "<a href='./.$filename.'>.$filename<img src='../document.png' /></a> <br>";
        }
    }
}
add_shortcode( 'scale-verification-certificate', 'scale_verification_certificate_func' );

Any help would be appreciated, Im sorry if I didnt write my question very well, its my first one :)

EDIT: I realise why its repeating 4 times now, because their are four folders, that start with that name, but no matter I would still appreciate help on the rest!

  • 写回答

1条回答 默认 最新

  • doupinwan0563 2019-04-27 05:36
    关注

    Since you figured out the 4x issue, in order for the function to return the string, you could just accumulate the results at each loop, and return a string in the end. Like so:

    function scale_verification_certificate_func($atts) {
        $current_user = wp_get_current_user();
        $ffield = FrmProEntriesController::get_field_value_shortcode(array(
                'field_id' => 140,
                'user_id' => 'current'));
    
        $ret_string = "";  // initialize empty string
        for ($i = 1; $i <= 10; $i++) {
            foreach (glob("./clients/Sites/" . $ffield . "/SCALE0". $i . "/*SCALE_VERIFICATION_CERTIFICATE*", GLOB_NOSORT) as $filename) {
                // at each loop, append new segment
                $ret_string .= "<a href='./.$filename.'>.$filename<img src='../document.png' /></a> <br>";
            }
        }
        return $ret_string;  // now return the full string
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 虚心请教几个问题,小生先有礼了
  • ¥30 截图中的mathematics程序转换成matlab