2014-09-26 1 views
0

Simple Lightbox 플러그인을 고급 사용자 정의 필드 이미지 필드에 통합하려고합니다.WP : acf 이미지 필드 및 간단한 라이트 박스 플러그인 통합

기본적으로 페이지의 모든 이미지 (acf 이미지 필드를 통해 채워짐)를 클릭하면 라이트 박스에서 열리 며 라이트 박스 내 다른 모든 이미지와 함께 그룹화하여 슬라이드 쇼처럼 탐색 할 수 있습니다. 이 기능은 Simple Lightbox 플러그인의 기본 제공 기능이지만 이미지 필드 용 템플릿 코드와 통합하는 방법을 알지 못합니다. 잘 작동하지만, 이미지 필드에 저를 벗어난 것이 적응 I이 사용하고 ACF WYSIWYG 필드에 대한

...

<?php 
    $content = get_field('wysiwyg'); 
    if (function_exists('slb_activate')) 
    $content = slb_activate($content); 
    echo $content; 
?> 

....

여기에 이미지 필드 내 템플릿 코드는 (단순 라이트 박스를 통합에서 어떤 시도없이)이다 : 이것으로 간단한 라이트 박스를 통합하는 방법에 대한

<?php 
    $image = get_field('img'); 

    if(! empty($image)) { 
    $url = $image['url']; 
    $alt = $image['alt']; 
    $caption = $image['caption']; 
    $size = 'large'; 
    $thumb = $image['sizes'][ $size ]; 
    $width = $image['sizes'][ $size . '-width' ]; 
?> 

<?php if($caption): ?> 

    <div class="wp-caption" style="width: <?php echo $width; ?>px"> 

<?php endif; ?> 

<a href="<?php echo $url; ?>"> 

    <img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>" /> 

</a> 

<?php if($caption): ?> 

     <p class="wp-caption-text"><?php echo $caption; ?></p> 

    </div> 

<?php endif; ?> 

<?php } ?> 

어떤 제안? 미리 감사드립니다!

답변

0

PHP 출력 버퍼링을 사용하여 템플릿을 변수에 저장하십시오. ob_start()를 맨 위에 놓은 다음 아래쪽에있는 ob_get_clean()은 출력 버퍼링을 중지하고 반환 값을 변수에 저장할 수 있습니다. 그런 다음 slb_activate로 전달합니다.

<?php 
    ob_start(); 

    $image = get_field('img'); 
    if(! empty($image)) { 
    $url = $image['url']; 
    $alt = $image['alt']; 
    $caption = $image['caption']; 
    $size = 'large'; 
    $thumb = $image['sizes'][ $size ]; 
    $width = $image['sizes'][ $size . '-width' ]; 
?> 
<?php if($caption): ?> 
    <div class="wp-caption" style="width: <?php echo $width; ?>px"> 
<?php endif; ?> 
<a href="<?php echo $url; ?>"> 
    <img src="<?php echo $thumb; ?>" alt="<?php echo $alt; ?>" /> 
</a> 
<?php if($caption): ?> 
     <p class="wp-caption-text"><?php echo $caption; ?></p> 
    </div> 
<?php endif; ?> 
<?php } ?> 
<?php $content = ob_get_clean(); ?> 
<?php echo slb_activate($content); ?> 
+0

내 업데이트 된 코드 참조. – manishie

+0

감사합니다. 그러나이 코드를 사용하면 불행히도 html 출력이 변경되지 않습니다. 출력은 위의 원래 코드를 사용할 때와 똑같습니다. 다른 아이디어? – dadra

+0

은 (가) 실수로 마지막 줄에 왔습니다. 이전에는 변경되지 않은 $ 콘텐츠가 반향되었습니다. 이것은 지금 작동해야합니다. – manishie