안녕하세요.
배너를 만들고 있는데 for 문에서 갯수를 끊어 나열하려 합니다
Copy
<div class="pic_lt_bottom">
<div class="owl-carousel-bottom owl-theme">
<?php
for ($i=0; $i<count($list); $i++) {
$thumb = get_list_thumbnail($bo_table, $list[$i]['wr_id'], $thumb_width, $thumb_height, false, true);
if($thumb['src']) {
$img = $thumb['src'];
} else {
$img = G5_IMG_URL.'/no_img.png';
$thumb['alt'] = '이미지가 없습니다.';
}
$img_content[$i] = '<img src="'.$img.'" alt="'.$thumb['alt'].'" >';
?>
<div class="item">
<a href="<?php echo $list[$i]['href'] ?>"><?php echo $img_content[$i]; ?></a>
</div>
<?php } ?>
<?php if (count($list) == 0) { //게시물이 없을 때 ?>
<li class="empty_li">게시물이 없습니다.</li>
<?php } ?>
</div>
</div>
<div class="item">
<a href="<?php echo $list[$i]['href'] ?>"><?php echo $img_content[$i]; ?></a>
</div>
for문 실행시 12개의 배너가 나오는데 6개씩 끊어서 놓으려고합니다
<div class="item">
<a href="<?php echo $list[$i]['href'] ?>"><?php echo $img_content[$i]; ?></a> - 처음부터 6번째까지
<a href="<?php echo $list[$i]['href'] ?>"><?php echo $img_content[$i]; ?></a> - 6번째부터 12번째까지
</div>
위와같이 실행하려면 어떻게 해야할까요?
|
답변 3개 / 댓글 7개
채택된 답변
+20 포인트
2019-03-05 (화) 10:34:26
<?
$list = array('a', 'b', 'c', 'd', 'e','a', 'b', 'c', 'd', 'e','a', 'b', 'c', 'd', 'e');
$chunk = array_chunk($list, 6);
?>
<div class="pic_lt_bottom">
<div class="owl-carousel-bottom owl-theme">
<?php for ($i=0; $i<count($chunk); $i++) { ?>
<div class="item">
<?foreach ($chunk[$i] as $key=>$val){
$thumb = get_list_thumbnail($bo_table, $val['wr_id'], $thumb_width, $thumb_height, false, true);
if($thumb['src']) {
$img = $thumb['src'];
} else {
$img = G5_IMG_URL.'/no_img.png';
$thumb['alt'] = '이미지가 없습니다.';
}
$img_content = '<img src="'.$img.'" alt="'.$thumb['alt'].'" >';
?>
<a href="<?php echo $val['href'] ?>"><?php echo $img_content; ?></a>
<?}?>
</div>
<?php } ?>
<?php if (count($list) == 0) { //게시물이 없을 때 ?>
<div class="empty_li">게시물이 없습니다.</div>
<?php } ?>
</div>
</div>
답변에 대한 댓글 7개
2019-03-05 (화) 11:32:22
2019-03-05 (화) 15:51:53
에러부분중
$thumb = get_list_thumbnail($bo_table, $val['wr_id'], $thumb_width, $thumb_height, false, true);
해당부분에서 에러가납니다 $val['wr_id']
$thumb = get_list_thumbnail($bo_table, $val['wr_id'], $thumb_width, $thumb_height, false, true);
해당부분에서 에러가납니다 $val['wr_id']
2019-03-05 (화) 16:01:44
음..에러나는 php파일의 소스 전부를 부탁드립니다. 제 갤러리 스킨에서 $list를 chunk로 끊었을때는 wr_id가 제대로 출력이 되거든요.
2019-03-05 (화) 17:40:56
<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
include_once(G5_LIB_PATH.'/thumbnail.lib.php');
// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
add_stylesheet('<link rel="stylesheet" href="'.$latest_skin_url.'/style.css">', 0);
$thumb_width = 386;
$thumb_height = 115;
?>
<link rel="stylesheet" href="<?php echo $latest_skin_url;?>/owl.carousel.min.css">
<link rel="stylesheet" href="<?php echo $latest_skin_url;?>/owl.theme.default.min.css">
<script src="<?php echo $latest_skin_url;?>/owl.carousel.js"></script>
<div class="pic_lt_bottom">
<div class="owl-carousel-bottom owl-theme">
<?php
for ($i=0; $i<count($list); $i++) {
$thumb = get_list_thumbnail($bo_table, $list[$i]['wr_id'], $thumb_width, $thumb_height, false, true);
if($thumb['src']) {
$img = $thumb['src'];
} else {
$img = G5_IMG_URL.'/no_img.png';
$thumb['alt'] = '이미지가 없습니다.';
}
$img_content[$i] = '<img src="'.$img.'" alt="'.$thumb['alt'].'" >';
?>
<div class="item">
<a href="<?php echo $list[$i]['href'] ?>"><?php echo $img_content[$i]; ?></a>
</div>
<?php } ?>
<?php if (count($list) == 0) { //게시물이 없을 때 ?>
<li class="empty_li">게시물이 없습니다.</li>
<?php } ?>
</div>
</div>
<script>
$(document).ready(function() {
var owl = $('.owl-carousel-bottom');
owl.owlCarousel({
loop: true,
margin: 20,
nav:false,
autoplay: true,
autoplayTimeout: 3000,
autoplayHoverPause: true,
responsiveClass:true,
responsive:{
0:{
items:1,
nav:false
},
500:{
items:2,
nav:false
},
1000:{
items:3,
nav:false,
}
}
});
// $('.play').on('click', function() {
// owl.trigger('play.owl.autoplay', [1000])
// })
// $('.stop').on('click', function() {
// owl.trigger('stop.owl.autoplay')
// })
})
</script>
이렇게 입니다.
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
include_once(G5_LIB_PATH.'/thumbnail.lib.php');
// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
add_stylesheet('<link rel="stylesheet" href="'.$latest_skin_url.'/style.css">', 0);
$thumb_width = 386;
$thumb_height = 115;
?>
<link rel="stylesheet" href="<?php echo $latest_skin_url;?>/owl.carousel.min.css">
<link rel="stylesheet" href="<?php echo $latest_skin_url;?>/owl.theme.default.min.css">
<script src="<?php echo $latest_skin_url;?>/owl.carousel.js"></script>
<div class="pic_lt_bottom">
<div class="owl-carousel-bottom owl-theme">
<?php
for ($i=0; $i<count($list); $i++) {
$thumb = get_list_thumbnail($bo_table, $list[$i]['wr_id'], $thumb_width, $thumb_height, false, true);
if($thumb['src']) {
$img = $thumb['src'];
} else {
$img = G5_IMG_URL.'/no_img.png';
$thumb['alt'] = '이미지가 없습니다.';
}
$img_content[$i] = '<img src="'.$img.'" alt="'.$thumb['alt'].'" >';
?>
<div class="item">
<a href="<?php echo $list[$i]['href'] ?>"><?php echo $img_content[$i]; ?></a>
</div>
<?php } ?>
<?php if (count($list) == 0) { //게시물이 없을 때 ?>
<li class="empty_li">게시물이 없습니다.</li>
<?php } ?>
</div>
</div>
<script>
$(document).ready(function() {
var owl = $('.owl-carousel-bottom');
owl.owlCarousel({
loop: true,
margin: 20,
nav:false,
autoplay: true,
autoplayTimeout: 3000,
autoplayHoverPause: true,
responsiveClass:true,
responsive:{
0:{
items:1,
nav:false
},
500:{
items:2,
nav:false
},
1000:{
items:3,
nav:false,
}
}
});
// $('.play').on('click', function() {
// owl.trigger('play.owl.autoplay', [1000])
// })
// $('.stop').on('click', function() {
// owl.trigger('stop.owl.autoplay')
// })
})
</script>
이렇게 입니다.
2019-03-05 (화) 18:09:54
<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
include_once(G5_LIB_PATH.'/thumbnail.lib.php');
// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
add_stylesheet('<link rel="stylesheet" href="'.$latest_skin_url.'/style.css">', 0);
$thumb_width = 386;
$thumb_height = 115;
$chunk_list = array_chunk($list,6);
?>
<link rel="stylesheet" href="<?php echo $latest_skin_url;?>/owl.carousel.min.css">
<link rel="stylesheet" href="<?php echo $latest_skin_url;?>/owl.theme.default.min.css">
<script src="<?php echo $latest_skin_url;?>/owl.carousel.js"></script>
<div class="pic_lt_bottom">
<div class="owl-carousel-bottom owl-theme">
<?php
for ($i=0; $i<count($chunk_list); $i++) {
?>
<div class="item">
<?foreach ($chunk_list[$i] as $key=>$val){
$thumb = get_list_thumbnail($bo_table, $val['wr_id'], $thumb_width, $thumb_height, false, true);
if($thumb['src']) {
$img = $thumb['src'];
} else {
$img = G5_IMG_URL.'/no_img.png';
$thumb['alt'] = '이미지가 없습니다.';
}
$img_content[$i] = '<img src="'.$img.'" alt="'.$thumb['alt'].'" >';
?>
<a href="<?php echo $val['href'] ?>"><?php echo $img_content[$i]; ?></a>
<?}?>
</div>
<?php } ?>
<?php if (count($list) == 0) { //게시물이 없을 때 ?>
<li class="empty_li">게시물이 없습니다.</li>
<?php } ?>
</div>
</div>
<script>
$(document).ready(function() {
var owl = $('.owl-carousel-bottom');
owl.owlCarousel({
loop: true,
margin: 20,
nav:false,
autoplay: true,
autoplayTimeout: 3000,
autoplayHoverPause: true,
responsiveClass:true,
responsive:{
0:{
items:1,
nav:false
},
500:{
items:2,
nav:false
},
1000:{
items:3,
nav:false,
}
}
});
// $('.play').on('click', function() {
// owl.trigger('play.owl.autoplay', [1000])
// })
// $('.stop').on('click', function() {
// owl.trigger('stop.owl.autoplay')
// })
})
</script>
이렇게 수정해보시겠어요. 크롬 디버거 켜보시면 div.item안에 ark 6개씩 들어갑니다.
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
include_once(G5_LIB_PATH.'/thumbnail.lib.php');
// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
add_stylesheet('<link rel="stylesheet" href="'.$latest_skin_url.'/style.css">', 0);
$thumb_width = 386;
$thumb_height = 115;
$chunk_list = array_chunk($list,6);
?>
<link rel="stylesheet" href="<?php echo $latest_skin_url;?>/owl.carousel.min.css">
<link rel="stylesheet" href="<?php echo $latest_skin_url;?>/owl.theme.default.min.css">
<script src="<?php echo $latest_skin_url;?>/owl.carousel.js"></script>
<div class="pic_lt_bottom">
<div class="owl-carousel-bottom owl-theme">
<?php
for ($i=0; $i<count($chunk_list); $i++) {
?>
<div class="item">
<?foreach ($chunk_list[$i] as $key=>$val){
$thumb = get_list_thumbnail($bo_table, $val['wr_id'], $thumb_width, $thumb_height, false, true);
if($thumb['src']) {
$img = $thumb['src'];
} else {
$img = G5_IMG_URL.'/no_img.png';
$thumb['alt'] = '이미지가 없습니다.';
}
$img_content[$i] = '<img src="'.$img.'" alt="'.$thumb['alt'].'" >';
?>
<a href="<?php echo $val['href'] ?>"><?php echo $img_content[$i]; ?></a>
<?}?>
</div>
<?php } ?>
<?php if (count($list) == 0) { //게시물이 없을 때 ?>
<li class="empty_li">게시물이 없습니다.</li>
<?php } ?>
</div>
</div>
<script>
$(document).ready(function() {
var owl = $('.owl-carousel-bottom');
owl.owlCarousel({
loop: true,
margin: 20,
nav:false,
autoplay: true,
autoplayTimeout: 3000,
autoplayHoverPause: true,
responsiveClass:true,
responsive:{
0:{
items:1,
nav:false
},
500:{
items:2,
nav:false
},
1000:{
items:3,
nav:false,
}
}
});
// $('.play').on('click', function() {
// owl.trigger('play.owl.autoplay', [1000])
// })
// $('.stop').on('click', function() {
// owl.trigger('stop.owl.autoplay')
// })
})
</script>
이렇게 수정해보시겠어요. 크롬 디버거 켜보시면 div.item안에 ark 6개씩 들어갑니다.
2019-03-08 (금) 11:47:12
아! 늦었지만 정말 감사드립니다! 덕분에 해결하였습니다 ㅠㅠ
많은도움 정말 감사드립니다! ㅠ
많은도움 정말 감사드립니다! ㅠ
Copy
for ($i=0; $i<count($list); $i++) {
$j = $i+1;
// 일반출력
if($j%6 == 0){
// 여섯번째마다
}
}
이렇게 하면 될거 같은데요 ^^;;
FullstackCreative
2019-03-05 (화) 09:41:20
간단히 <br>로 끊었습니다.
Copy
<div class="pic_lt_bottom">
<div class="owl-carousel-bottom owl-theme">
<div class="item">
<?php
for ($i=0; $i<count($list); $i++) {
$thumb = get_list_thumbnail($bo_table, $list[$i]['wr_id'], $thumb_width, $thumb_height, false, true);
if($thumb['src']) {
$img = $thumb['src'];
} else {
$img = G5_IMG_URL.'/no_img.png';
$thumb['alt'] = '이미지가 없습니다.';
}
$img_content[$i] = '<img src="'.$img.'" alt="'.$thumb['alt'].'" >';
?>
<a href="<?php echo $list[$i]['href'] ?>"><?php echo $img_content[$i]; ?></a>
<?php
if ($i=='5'){ echo '<br>'; }
}
?>
<?php if (count($list) == 0) { //게시물이 없을 때 ?>
게시물이 없습니다.
<?php } ?>
</div>
</div>
</div>
답변을 작성하려면 로그인이 필요합니다.
Illegal string offset 'wr_id' in 에러가 납니다 ㅠ