2013-08-20 2 views
0

검색어로 이미지 URL을 가져 와서 같은 페이지의 꼬리말에있는 플러그인 스크립트에 해당 URL을 표시하도록 할 수 있습니까? 내 문제는 정적 레이어 이미지가 필요한 레이어 라이더가 있다는 것입니다. 문제는 쿼리가 페이지 상단에서 실행되므로 꼬리말에서 자바 스크립트가 호출 될 때까지 루프에 액세스 할 수 없게된다는 것입니다.WordPress의 추천 이미지 URL을 바닥 글 스크립트로 가져 오기

<script type="text/javascript"> 
    //Layer Slider 
     $(document).ready(function(){ 
     $('#layerslider').layerSlider({ 
     globalBGImage: '<?php echo $imagefromloopurlhere; ?>' 
    }); 
    }); 
</script> 
:

/*Normal Page Loop Here*/ 
if (have_posts()) : while (have_posts()) : the_post(); 

/*Begin Secondary Query to be Inserted into this page*/ 
$args = array(
'post_type' => 'projects', 
'orderby' => 'rand', 
'posts_per_page' => 1, 
'meta_query' => array(
      array(
      'key' => 'custom_featured', 
      'value' => 'on', 
      ) 
     ) 
); 
$my_query = new WP_Query($args); 


    /*Output Results of Internal Page Query*/ 
if($my_query->have_posts()) { 
    while ($my_query->have_posts()) : $my_query->the_post(); ?> 
     the_title(); 
     the_post_thumbnail('i-need-this-url-in-the-footer-script');   

    endwhile;/*End the secondary query loop*/ 
    wp_reset_query(); 


endwhile; endif;/*End the page loop*/  

나는 기본적으로 바닥 글의 스크립트 삽입이 새로운 WP_Query의 기능 이미지의 URL이 필요합니다

나는이 쿼리, 일반 페이지 루프의 내부를 가지고

답변

3

이 이미지는 같은 것을 할 수있는 바닥 글에 변수를 배치하기 위해

$image_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'thumbnail_size'); 
if($image_src) 
    echo $image_src[0]; 

의 URL 얻을 것이다 :

다음
global $project_featured_url; 
while ($my_query->have_posts()) : $my_query->the_post(); 
    the_title(); 
    $image_src = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'thumbnail_size'); 
    if($image_src) 
     $project_featured_url = $image_src[0]; 
    else 
     $project_featured_url = 'some default url to avoid javascript error'; 
endwhile;/*End the secondary query loop*/ 

당신의 바닥 글을

<?php global $project_featured_url; ?> 
<script type="text/javascript"> 
    //Layer Slider 
     $(document).ready(function(){ 
     $('#layerslider').layerSlider({ 
     globalBGImage: '<?php echo $project_featured_url; ?>' 
    }); 
    }); 
</script> 
+0

아쉽게도 배열을 반환 중입니다 – TripsLeft

+0

배열에서 이미지 원본 url을 에코하도록 업데이트되었습니다. – Simalam

+0

코드를 업데이트했습니다. 내 바닥 글에 스크립트에 삽입 된 일반 페이지 루프 안에 실제로있는 새 WP_Query의 이미지 URL을 가져 오려고합니다. 귀하가 게시 한 코드는 실제 페이지 자체의 특색있는 이미지 URL을 얻는 것입니다. – TripsLeft

0

이 작동합니다 ....

<?php get_the_post_thumbnail($post->ID, 'thumbnail'); ?> 

는 당신이 필요로하는 이미지 크기로 축소 변경 .