\r\n\r\n \r\n\r\n
\r\n\r\n ...","dateCreated":"2024-08-12T17:58:09+09:00","author":{"@type":"Person","name":"jpna"},"answerCount":3,"suggestedAnswer":[{"@type":"Answer","text":"[code]\r\n
';?>
\r\n\r\n// if($view['file'][9]['path']) 해당 조건을 div 밖으로 이동하세요.\r\n\r\n \r\n\r\n\r\n\r\n
';?>
\r\n\r\n[/code]\r\n\r\n도움이 되셨다면 채택 한번 부탁드립니다^^\r\n","author":{"@type":"Person","name":"테트라포드"},"dateCreated":"2024-08-12T18:21:47+09:00"},{"@type":"Answer","text":"[code]\r\n\r\n\r\n\r\n[/code]\r\n\r\n \r\n","author":{"@type":"Person","name":"RYANRYAN"},"dateCreated":"2024-08-12T18:02:58+09:00"}],"acceptedAnswer":{"@type":"Answer","text":"다음 코드가 도움이 될지 모르겠습니다.\r\n\r\n \r\n\r\n[code]\r\n\r\n\r\n\r\n \r\n\r\n
\r\n\r\n   
\r\n\r\n     
채택완료

문의드립니다.

아래는 첨부파일을 등록하면 뷰화면에서 왼쪽으로 이미지가 슬라이드 하는 소스입니다. 첨부파일이 총 10개까지 등록이 가능한데, 아래소스 중 7,8,9,10번째의 첨부파일을 등록하지 않으면 해당 div가 보이지 않게 하려는데 아래 소스로 테스트 하면 7,8,9,10번째에 빈div가 보이네요. 어떻게 해야 할까요?

 

<script>

      $( document ).ready( function() {

        $( '.swiper .swiper-wrapper .swiper-slide:empty' ).css("display", "none");

      } );

</script>

 

<div class="swiper mySwiper">

    <div class="swiper-wrapper">

      <div class="swiper-slide"><?php if($view['file'][0]['path']) echo '<img src="'.$view['file'][0]['path'].'/'.$view['file'][0]['file'].'">';?></div>

      <div class="swiper-slide"><?php if($view['file'][1]['path']) echo '<img src="'.$view['file'][1]['path'].'/'.$view['file'][1]['file'].'">';?></div>

      <div class="swiper-slide"><?php if($view['file'][2]['path']) echo '<img src="'.$view['file'][2]['path'].'/'.$view['file'][2]['file'].'">';?></div>

      <div class="swiper-slide"><?php if($view['file'][3]['path']) echo '<img src="'.$view['file'][3]['path'].'/'.$view['file'][3]['file'].'">';?></div>

      <div class="swiper-slide"><?php if($view['file'][4]['path']) echo '<img src="'.$view['file'][4]['path'].'/'.$view['file'][4]['file'].'">';?></div>

      <div class="swiper-slide"><?php if($view['file'][5]['path']) echo '<img src="'.$view['file'][5]['path'].'/'.$view['file'][5]['file'].'">';?></div>

      <div class="swiper-slide"><?php if($view['file'][6]['path']) echo '<img src="'.$view['file'][6]['path'].'/'.$view['file'][6]['file'].'">';?></div>

      <div class="swiper-slide"><?php if($view['file'][7]['path']) echo '<img src="'.$view['file'][7]['path'].'/'.$view['file'][7]['file'].'">';?></div>

      <div class="swiper-slide"><?php if($view['file'][8]['path']) echo '<img src="'.$view['file'][8]['path'].'/'.$view['file'][8]['file'].'">';?></div>

      <div class="swiper-slide"><?php if($view['file'][9]['path']) echo '<img src="'.$view['file'][9]['path'].'/'.$view['file'][9]['file'].'">';?></div>

    </div>

    

    <div class="swiper-button-next"></div>

    <div class="swiper-button-prev"></div>

    

  </div>

|

답변 3개 / 댓글 6개

채택된 답변
+20 포인트

다음 코드가 도움이 될지 모르겠습니다.

 

Copy
<script>

//      $( document ).ready( function() {

//        $( '.swiper .swiper-wrapper .swiper-slide:empty' ).css("display", "none");

//      } );

</script>

 

<div class="swiper mySwiper">

    <div class="swiper-wrapper">

      <?php
      for ($i = 0; $i < 10; $i++) {
        if(empty($view['file'][$i]['path']) == false && empty($view['file'][$i]['file']) == false) {
          $imgsrc = $view['file'][$i]['path'].'/'.$view['file'][$i]['file'];
      ?>
        <div class="swiper-slide"><img src="<?php echo $imgsrc; ?>"></div>
      <?php
        }
      }
      ?>

    </div>

    

    <div class="swiper-button-next"></div>

    <div class="swiper-button-prev"></div>

    

  </div>

답변에 대한 댓글 1개

아래 분들도 모두 도움이 되었습니다.
하지만 이 코드가 제일 깔끔하군요.
감사합니다.

Copy
<div class="swiper-slide"><?php if($view['file'][9]['path']) echo '<img src="'.$view['file'][9]['path'].'/'.$view['file'][9]['file'].'">';?></div>

// if($view['file'][9]['path']) 해당 조건을 div 밖으로 이동하세요.

 


<?php if($view['file'][9]['file']){ ?>
<div class="swiper-slide"><?php echo '<img src="'.$view['file'][9]['path'].'/'.$view['file'][9]['file'].'">';?></div>
<? } ?>


도움이 되셨다면 채택 한번 부탁드립니다^^

답변에 대한 댓글 1개

잘되네요.
도움주셔서 감사합니다.

Copy
<script>


$( document ).ready( function() {

  $( '.swiper .swiper-wrapper .swiper-slide' ).each(function() {
    if ($(this).find('img').length == 0) {
      $(this).css("display", "none");
    }
  });

} );

</script>

 

답변에 대한 댓글 4개

변화가 없네요. 계속 빈페이지가 보이네요.
$( document ).ready( function() {

$( '.swiper .swiper-wrapper .swiper-slide' ).each(function() {
if ($(this).find('img').attr('src') == "") {
$(this).hide();
}
});

} );

또는

$( document ).ready( function() {

$( '.swiper .swiper-wrapper .swiper-slide' ).each(function() {
if ($(this).find('img').attr('src') == "/") {
$(this).hide();
}
});

} );

로 바꿔보세요
관심 가져주셔서 감사합니다. 역시 안되네요.
어렵네요. 안되네요.

답변을 작성하려면 로그인이 필요합니다.