I have a view that selects a random image url. Id like to use the url as an inline css background image.
I've got this function working to add the div but am having a hard time crafting the right php to insert the view. Admittedly I'm not that strong in the php arena. Can you see if I have this crafted correctly?
function griffin_before_header_wrap() {
echo '<div class="home-header_wrap" style="background-image:"url(".do_shortcode( '[wpv-view name="homepagebackgroundimage"]');.>';
}
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
Hi Steve
It looks like you are getting muddled with single and double quotes.
Easier to extract the call to do the wpv-view shortcode to keep things simpler.
Note that in PHP variables inside double-quotes are evaluated, so I switched your quotes around, too.
function griffin_before_header_wrap() {
$url = do_shortcode( '[wpv-view name="homepagebackgroundimage"]' );
echo "<div class='home-header_wrap' style='background-image: url( $url )'>";
}
Is that what you are after?
Yes thats closer however it generates this- can all of the other view markup be suppressed somehow
<div class="home-header_wrap" style="background-image: url(
<div id="wpv-view-layout-78738" class="js-wpv-view-layout js-wpv-layout-responsive js-wpv-view-layout-78738" data-viewnumber="78738" data-pagination="{"id":"78738","query":"normal","type":"disabled","effect":"fade","duration":500,"speed":5,"pause_on_hover":"enabled","stop_rollover":"false","cache_pages":"enabled","preload_images":"enabled","preload_pages":"enabled","preload_reach":1,"spinner":"builtin","spinner_image":"hidden link ","callback_next":"","manage_history":"disabled","has_controls_in_form":"disabled","infinite_tolerance":"0","max_pages":1,"page":1,"base_permalink":"/?wpv_view_count=78738&wpv_paged=WPV_PAGE_NUM","loop":{"type":"","name":"","data":[],"id":0}}" data-permalink="/?wpv_view_count=78738">
hidden link
</div>
)">
My loop just contains
[types field='home-page-header-image' output='raw'][/types]
Nigel
Supporter
Languages:
English (English )
Spanish (Español )
Timezone:
Europe/London (GMT+00:00)
You can output a "naked" View with the setting shown in the screenshot...
My issue is resolved now. Thank you!