Skip Navigation

[Resolved] using a view inside a wordpress function

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 4 replies, has 2 voices.

Last updated by Steve 1 year, 8 months ago.

Assisted by: Nigel.

Author
Posts
#2577743

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"]');.>';
}

#2577841

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?

#2577873

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]

#2578265

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screenshot 2023-03-22 at 07.28.46.png

You can output a "naked" View with the setting shown in the screenshot...

#2578789

My issue is resolved now. Thank you!