Add a separator to file

Support General Add a separator to fileResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #35596
    IacopoIacopo
    Participant

    Hi, I have that code

    <?php
    $files = rwmb_meta( 'planimetrie' );
    foreach ( $files as $file ) {
        ?>
        <a>" target="_blank"><?php echo $file['name']; ?></a>
        <?php
    }
    ?>

    that retrieve a file list and open it in a new blank page, but i'm not sure where place the separator to have: file1, file2...

    Anyone can help? thanks

    #35606
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You can just add the separator after the closing tag </a>

    <a href="<?php echo $file['url']; ?>" target="_blank"><?php echo $file['name']; ?></a>,

    #35631
    IacopoIacopo
    Participant

    It's working, but that add the ',' after the last file. How I can add a separator only to the other list file?

    #35652
    Long NguyenLong Nguyen
    Moderator

    Hi,

    You can count the number of files then check in the loop if reach the last file and remove the separator. Just like

    $files = rwmb_meta( 'planimetrie' );
    $count = count( $files );
    $i = 1;
    foreach ( $files as $file ) {
        if( $i < $count ) {
        	?>
    	    <a href="<?php echo $file['url']; ?>" target="_blank"><?php echo $file['name']; ?></a>,
    	    <?php
        } else {
        	?>
    	    <a href="<?php echo $file['url']; ?>" target="_blank"><?php echo $file['name']; ?></a>
    	    <?php
        } 
        $i++;
    }
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.