Skip Navigation

[Resolved] Disabling Views wrapper divs in Views 2.4.0

This support ticket is created 6 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

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+01:00)

This topic contains 4 replies, has 2 voices.

Last updated by Simon 6 years, 11 months ago.

Assisted by: Nigel.

Author
Posts
#531263

Ever since you introduced 'wrapper divs' to help pagination, they have caused us problems with more sophisticated applications of Views.

Now, I have had to upgrade a website from Views 1.10 to 2.4.0 because I can no longer justify not upgrading WordPress.

SO, I NEED TO DISABLE THE WRAPPER DIVS FROM VIEWS OUTPUT ON A GLOBAL BASIS.

I am unable to find a working solution here on the forums, and there is no mention in the documentation that I can find.

We raised this issue last year - https://toolset.com/forums/topic/when-will-you-add-the-option-to-remove-the-wrapper-div-around-each-view/ - and it has not stopped being a problem.

This solution does not work (Views output disappears completely):
https://toolset.com/forums/topic/disabling-new-view-wrapper-div-in-views-1-11/

I am not convinced this solution works, and it has to be set up for each View which is simply not practical:
https://toolset.com/forums/topic/views-not-working-after-installing-v1-11/

It must be possible to provide a global function to disable this markup, which causes us nothing but problems.

Your urgent assistance much appreciated.

#531266

The issue is also raised in this thread: https://toolset.com/forums/topic/problem-with-view-wrapper-div-override-after-views-1-12-upgrade/

I am not convinced this modified solution works any more either.

Adriano says this will be discussed with the developers but I suspect this didn't happen.

#531406

Nigel
Supporter

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

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

Hi Simon

The issue is on our roadmap and it will be implemented—an increasing number of clients want a clean output of Views in JSON format, for example—but I can't say when.

In the meantime you can add the following code which will strip the wrapper div from any View output (only the content between <!-- wpv-loop-start --> and <!-- wpv-loop-end --> in the Loop Output section will be rendered.

Note that functionality which depends on the wrapper (e.g. filters and pagination) will no longer work.

/**
 * Naked Views output with no wrapper divs
 */
add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_naked_view_output', 5, 2 );
function prefix_naked_view_output( $out, $view_id ) {

	if ( true ) { // add test for View ID if required
		$start = strpos( $out, '<!-- wpv-loop-start -->' );
		if	( 	$start !== false
				&& 
				strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false ) {

			$start = $start + strlen( '<!-- wpv-loop-start -->' );
			$out = substr( $out , $start );
			$end = strrpos( $out, '<!-- wpv-loop-end -->' );
			$out = substr( $out, 0, $end );
		}
	}

	return $out;
}

I just tested the code on a local site and it worked as expected, but let me know if you have problems with it.

And don't forget to backup before making such a large version change of Views.

#531425

That is working for me, thank you

Can I recommend that a note about this be added somewhere to the documentation?

#533357

For the benefit of other users, we have a version of this solution we implemented which only targets specific Views based on ID:

/**
 * Naked Views output with no wrapper divs - SPECIFY WHICH VIEWS TO TARGET
 */
add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_naked_view_output', 5, 2 );
function prefix_naked_view_output( $out, $view_id ) {
    $views_to_target = array(599,3948,3026,);// replace with comma separated list of View IDs
    if ( in_array($view_id, $views_to_target)) { // add test for View ID
        $start = strpos( $out, '<!-- wpv-loop-start -->' );
        if  (   $start !== false
                && 
                strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false ) {
 
            $start = $start + strlen( '<!-- wpv-loop-start -->' );
            $out = substr( $out , $start );
            $end = strrpos( $out, '<!-- wpv-loop-end -->' );
            $out = substr( $out, 0, $end );
        }
    }
 
    return $out;
}
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.