有没有办法从查询中拉出图片url,并将该url回显到同一页面的页脚中的插件脚本?我的问题是我有一个需要静态背景图像的图层滑块。问题在于查询运行在页面顶部,因此在页脚中调用javascript时,我无法访问该循环。获取wordpress特色图片URL到页脚脚本
我有这个疑问,正常的页面循环内:
/*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>
不幸的是,这是返回一个数组 – TripsLeft
已更新,以回显数组中的图像源url – Simalam
我已更新我的代码。我试图将新插入的WP_Query的图像URL插入脚本中的脚本中。您发布的代码正在获取实际页面本身的精选图片网址 – TripsLeft