์๋
!
์... ๋ด Wordpress ๊ฒ์๋ฌผ์ ํฌํจ๋ ์ฌ์ง์ ๋ฐ๋ผ ์ฌ๋ฌ ๋์ ๊ฐค๋ฌ๋ฆฌ๋ฅผ ์ธ์คํด์คํํ๋ ค๊ณ ํฉ๋๋ค.
๋ฌธ์์ ์ธํฐ๋ท์์ ๋ณด๋ ค๊ณ ํ์ง๋ง ๋์ ๋ชจ๋๋ฅผ ์ฌ์ฉํ๋ ์ฌ๋ฌ ์ธ์คํด์ค์ ๋ํ ์ธ๊ธ์ด ์์ต๋๋ค.
๋์์ ์ฃผ์
์ ๋ฏธ๋ฆฌ ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
ํธ์ง : ๋๋ WordPress์์ v2๋ฅผ ์๋์ํฌ ์์๋ ํ ๋ฒ์ 1.6.0์ ์ฌ์ฉํ๊ณ ์์ต๋๋ค ...
๋๋ ๋จ์ง ๋ผ์ดํธ ๊ฐค๋ฌ๋ฆฌ์ ๊ด๋ จ ์ธ์คํด์ค๋ฅผ ์์ํ ์ ์๋ ๋ฒํผ์ ์ ๊ณตํ๊ณ ์ถ๊ธฐ ๋๋ฌธ์ ๋์ ์ธ์คํด์ค๋ฅผ ๋ชฉํ๋ก ํ๊ณ ์์ต๋๋ค.
๋ฌธ์ ๋ ์์ฑ๋ ์ฝ๋๊ฐ ์ฌ๋ฐ๋ฅธ ๊ฒ์ฒ๋ผ ๋ณด์ด์ง๋ง(๊ทธ๋ ์ง ์์ ์๋ ์์ง๋ง ๋ด๊ฐ ๋ง์น ๋ถ๋ถ์ด ํ์๋์ง ์์) ๋ฒํผ์ ํด๋ฆญํ๋ฉด ํญ์ ๋์ผํ ๊ฐค๋ฌ๋ฆฌ ํ์ ์ด ํ์๋๋ค๋ ๊ฒ์ ๋๋ค.
<div class="slides price">
<div class="slide">
<div class="bodytext">
<button type="button" id="dynamic2002">2002</button>
<script>
var gallery2002 = [
{
src: '*****/wp-content/uploads/2021/04/IMG_0116-1024x768.jpg',
thumb: '*****/wp-content/uploads/2021/04/IMG_0116-1024x768.jpg',
},
{
src: '*****/wp-content/uploads/2021/04/IMG_0117-1024x768.jpg',
thumb: '*****/wp-content/uploads/2021/04/IMG_0117-1024x768.jpg',
},
{
src: '*****/wp-content/uploads/2021/04/IMG_0326-1024x768.jpg',
thumb: '*****/wp-content/uploads/2021/04/IMG_0326-1024x768.jpg',
},
{
src: '*****/wp-content/uploads/2021/04/IMG_0327-1024x768.jpg',
thumb: '*****/wp-content/uploads/2021/04/IMG_0327-1024x768.jpg',
}
];
jQuery('#dynamic2002').on('click', function() {
jQuery(this).lightGallery({
hash: false,
dynamic: true,
dynamicEl: gallery2002,
galleryId: 1
});
});
</script>
</div>
</div>
<div class="slide">
<div class="bodytext">
<button type="button" id="dynamic1964">1964</button>
<script>
var gallery1964 = [
{
src: '*****/wp-content/uploads/2021/03/IMG_0367.jpg',
thumb: '*****/wp-content/uploads/2021/03/IMG_0367.jpg',
},
{
src: '*****/wp-content/uploads/2021/03/IMG_0368-1024x768.jpg',
thumb: '*****/wp-content/uploads/2021/03/IMG_0368-1024x768.jpg',
},
{
src: '*****/wp-content/uploads/2021/03/IMG_0369-1024x768.jpg',
thumb: '*****/wp-content/uploads/2021/03/IMG_0369-1024x768.jpg',
},
{
src: '*****/wp-content/uploads/2021/03/IMG_0370-768x1024.jpg',
thumb: '*****/wp-content/uploads/2021/03/IMG_0370-768x1024.jpg',
}
];
jQuery('#dynamic1964').on('click', function() {
jQuery(this).lightGallery({
hash: false,
dynamic: true,
dynamicEl: gallery1964,
galleryId: 2
});
});
</script>
</div>
</div>
์๋ ํ์ธ์ @dphermes ,
lightGallery 1.x ๊ตฌ๋ฌธ์ ์ฌ์ฉํ๊ณ ์๋ ๊ฒ ๊ฐ์ต๋๋ค. lightGallery 2.x์๋ jQuery๊ฐ ํ์ํ์ง ์์ต๋๋ค.
๋ฐ๋ชจ - https://www.lightgalleryjs.com/demos/dynamic-mode/
๋ฌธ์ - https://www.lightgalleryjs.com/docs/dynamic-variables/
์๋ ์ฝ๋ ์ค๋ํซ์ ์ ๋๋ก ์๋ํด์ผ ํฉ๋๋ค.
<div class="slides price">
<div class="slide">
<div class="bodytext">
<button type="button" id="dynamic2002">2002</button>
<script>
var gallery2002 = [
{
src: '*****/wp-content/uploads/2021/04/IMG_0116-1024x768.jpg',
thumb: '*****/wp-content/uploads/2021/04/IMG_0116-1024x768.jpg',
},
{
src: '*****/wp-content/uploads/2021/04/IMG_0117-1024x768.jpg',
thumb: '*****/wp-content/uploads/2021/04/IMG_0117-1024x768.jpg',
},
{
src: '*****/wp-content/uploads/2021/04/IMG_0326-1024x768.jpg',
thumb: '*****/wp-content/uploads/2021/04/IMG_0326-1024x768.jpg',
},
{
src: '*****/wp-content/uploads/2021/04/IMG_0327-1024x768.jpg',
thumb: '*****/wp-content/uploads/2021/04/IMG_0327-1024x768.jpg',
}
];
const dynamicGal1 = lightGallery( jQuery('#dynamic2002')[0], {
hash: false,
dynamic: true,
dynamicEl: gallery2002,
galleryId: 1
});
jQuery('#dynamic2002').on('click', function() {
dynamicGal1.openGallery();
});
</script>
</div>
</div>
<div class="slide">
<div class="bodytext">
<button type="button" id="dynamic1964">1964</button>
<script>
var gallery1964 = [
{
src: '*****/wp-content/uploads/2021/03/IMG_0367.jpg',
thumb: '*****/wp-content/uploads/2021/03/IMG_0367.jpg',
},
{
src: '*****/wp-content/uploads/2021/03/IMG_0368-1024x768.jpg',
thumb: '*****/wp-content/uploads/2021/03/IMG_0368-1024x768.jpg',
},
{
src: '*****/wp-content/uploads/2021/03/IMG_0369-1024x768.jpg',
thumb: '*****/wp-content/uploads/2021/03/IMG_0369-1024x768.jpg',
},
{
src: '*****/wp-content/uploads/2021/03/IMG_0370-768x1024.jpg',
thumb: '*****/wp-content/uploads/2021/03/IMG_0370-768x1024.jpg',
}
];
const dynamicGal2 = lightGallery( jQuery('#dynamic1964')[0], {
hash: false,
dynamic: true,
dynamicEl: gallery1964,
galleryId: 2
});
jQuery('#dynamic1964').on('click', function() {
dynamicGal2.openGallery();
});
</script>
</div>
</div>
๋ฌธ์ ๊ฐ ๋ฐ์ํ๋ฉด ์๋ ค์ฃผ์ญ์์ค.
ํ์ธ. ์์ ๋ณธ๋ง ๋ดค์ต๋๋ค. ์ฝ๋๊ฐ ์ข์ ๋ณด์ ๋๋ค.
1.x๋ก codepen ๋ฐ๋ชจ๋ฅผ ๋ง๋ค์์ต๋๋ค - https://codepen.io/sachinchoolur/pen/qryByV
2.x๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ์ข์ต๋๋ค. 2.x์์ ์ด๋ค ์ค๋ฅ๊ฐ ๋ฐ์ํ๋์ง ์๋ ค์ฃผ์๋ฉด ์๋ฃจ์ ์ ์ ๊ณตํ๋๋ก ๋ ธ๋ ฅํ๊ฒ ์ต๋๋ค.
ํ ... ์ฌ์ค ์ ๋ 1.6.0 ๋ฒ์ ์ ์ฌ์ฉํ๊ธฐ๋ก ๊ฒฐ์ ํ์ต๋๋ค. ์ฝ๋๊ฐ php์์ ์์ฑ๋๊ณ id ๋ณ์์ ์ด๋ฏธ์ง URL์ด ์๋ํ๋ ์ค ํ ํ๋ฆฟ php ํ์ผ์ ์คํฌ๋ฆฝํธ ํ๊ทธ์์ php๋ก ํธ์๋ฉ๋๋ค.
<script>
var gallery<?= get_the_ID(); ?> = [
<?php
$media = get_attached_media('image');
foreach(array_slice($media, 0, 6) as $m) {
$mee = wp_get_attachment_image_src($m->ID, 'large');
echo '{
src: \''.$mee[0].'\',
thumb: \''.$mee[0].'\',
},';
}
?>
];
const dynamicGal<?= $i ?> = lightGallery( jQuery('#dynamic<?= get_the_ID(); ?>')[0], {
dynamic: true,
dynamicEl: gallery<?= get_the_ID(); ?>,
galleryId: <?= $i ?>
});
jQuery('#dynamic<?= get_the_ID(); ?>').on('click', function() {
dynamicGal<?= $i ?>.openGallery();
});
</script>
๋ฌธ์ ๋ 2.x์์ ReferenceError: Can't find variable: lightGallery
์ค๋ฅ๊ฐ ๋ฐ์ํ๋ค๋ ๊ฒ์
๋๋ค.
์ง๊ธ ๋ฐ๋ก codepen ๋ฐ๋ชจ๋ฅผ ํ์ธํ๊ฒ ์ต๋๋ค ;) ๊ฐ์ฌํฉ๋๋ค
v2.x์์ ReferenceErrors๊ฐ ์ฌ๋ผ์ง๊ฒ ๋ง๋ค์์ต๋๋ค.
์ฌ์ ํ ๊ฐ์ ๊ฐค๋ฌ๋ฆฌ๋ฅผ ์์ํ์ง๋ง...
๊ฐค๋ฌ๋ฆฌ๋ฅผ ๋ณด๊ณ ์ถ๋ค๋ฉด ์ฌ๊ธฐ ๋ฅผ ํด๋ฆญํ์ธ์... ์ฌ๋ผ์ด๋์ ํ์ ์์ญ(์ฌ์ง ๋๋ YT ๋น๋์ค ์๋)์ id(์: 2002)๊ฐ ํฌํจ๋ ๋ฒํผ์ ํด๋ฆญํ์ฌ ๊ฐค๋ฌ๋ฆฌ๋ฅผ ์คํํ๋ ค๊ณ ํฉ๋๋ค.
์ด๊ฒ์ "2002" ๋ฒํผ์ด ํญ์ ๋ค๋ฅธ ๋ชจ๋ ๋ฒํผ ์์ ์๊ธฐ ๋๋ฌธ์ ๋ค๋ฅธ ๋ฒํผ์ ํด๋ฆญํ ์ ์๊ธฐ ๋๋ฌธ์ ๋ฐ์ํฉ๋๋ค.
ํ๊ฒฉ CSS๋ฅผ ์ถ๊ฐํ๋ฉด ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋ฉ๋๋ค.
.slides.price .slide.current {
z-index: 9;
}
.slides.price .slide {
background-color: #333;
}
ํธ.. ๊ทธ๊ฑธ ์ด๋ป๊ฒ ๋ชป ๋ดค์ด? CSS๋ฅผ ์ํด์ผ ํฉ๋๋ค. ๋ฉํ ๋๋... ํํ!
๋ง์ ๋์์ ์ฃผ์
์ ๊ฐ์ฌํ๊ณ ๋๋ฌด ๋นจ๋ฆฌ ์๋ตํด ์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค ;)
๋์์ด ๋์๋ค๋ ๋คํ์ ๋๋ค ๐