Skip Navigation

[Resolved] Raw Output of Views Loop

This thread is resolved. Here is a description of the problem and solution.

Problem:
The Views Loop seems to wrap the output always in some Default HTML.
Can this be removed?

Solution:
https://toolset.com/forums/topic/cruft-output-by-views/#post-610342

This support ticket is created 6 years, 10 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by Paul 6 years, 10 months ago.

Assisted by: Beda.

Author
Posts
#610283

When I use Views loop wizard to create a template the content is surrounded by a div such as the example below. I guess a lot of this stuff is for pagination of multiple pages of results which I am not needing. Is it possible to not output this div and only output the markup I define?

<div id="wpv-view-layout-31-CATTRc09fc0679f1ba05a10da6a0a34e14bcfTCPID9" class="js-wpv-view-layout js-wpv-layout-responsive js-wpv-view-layout-31-CATTRc09fc0679f1ba05a10da6a0a34e14bcfTCPID9" data-viewnumber="31-CATTRc09fc0679f1ba05a10da6a0a34e14bcfTCPID9" data-pagination="{"id":"31","base_permalink":"/?wpv_view_count=31-CATTRc09fc0679f1ba05a10da6a0a34e14bcfTCPID9&wpv_paged=WPV_PAGE_NUM","query":"normal","type":"disabled","effect":"fade","duration":500,"speed":5,"pause_on_hover":"disabled","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":"enabled","has_controls_in_form":"disabled","infinite_tolerance":"0","max_pages":1,"page":1,"loop":{"type":"","name":"","data":[],"id":0}}" data-permalink="/?wpv_view_count=31-CATTRc09fc0679f1ba05a10da6a0a34e14bcfTCPID9">

#610342
Bildschirmfoto-2015-11-04-um-19.10.47-150x150-2.png

No, that is not possible to remove, and I cannot suggest to remove it either.

It is needed for several identifications of the View, it's pagination, Search, AJAX requests, and more.

Now, if you really need to have it gone, you can apply a PHP Filter which is elaborated below, but please acknowledge the several risks outline.

1. The Filter

add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );

function prefix_clean_view_output( $out, $id ) {
if ( $id == '375' ) { //Change this to your 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;
}

2. Use a Views Loop similar to the screenshot

3. Risks and warnings:
- It hooks early in the View output.
- Priority 5 is mandatory
- It only affects a View with an ID of 375, adjust acordingly if needed.
- It only affects Views with actual results: if the View matches no result, the same “No items found” or whatever you have between the wpv-no-items-found shortcode applies.
- It returns only what is between the HTML comments <!– wpv-loop-start –> and <!– wpv-loop-end –> , excluding them. Only content between those HTML comments is returned, as is.
- Notice that, with this applied to a given View ID:
-- Pagination, specially AJAX pagination, will not work.
-- Parametric search, specially AJAXed parametric search, will not work.
-- Other future features will not work either.

So this is to be used if and only if you know what you are doing and you are going to use the View output as source for anything else.

But also notice that this only clears the View structure.

Building as example JSON inside a View output is wrong because we can not address quoting problems.

Please use this with caution.

#610362

Thanks for your help, thats useful.