クエリから画像の URL を取得し、その URL を同じページのフッターにあるプラグイン スクリプトにエコーする方法はありますか? 私の問題は、静的な背景画像を必要とするレイヤースライダーがあることです。問題は、クエリがページの上部で実行されるため、フッターで JavaScript が呼び出されるまでにループにアクセスできなくなることです。
通常のページループの内側に、次のクエリがあります。
/*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 が必要です。
<script type="text/javascript">
//Layer Slider
$(document).ready(function(){
$('#layerslider').layerSlider({
globalBGImage: '<?php echo $imagefromloopurlhere; ?>'
});
});
</script>