Skip Navigation

[Resolved] How to display view results inline (or specify div class)

This support ticket is created 8 years, 4 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
- - 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 5 replies, has 2 voices.

Last updated by Beda 8 years, 4 months ago.

Assisted by: Beda.

Author
Posts
#350715

When I built this page layout hidden link I think the Views output was working differently - the names of the authors were displaying inline (i.e. as a raw Views output without the enclosing DIV) in the enclosing DIV in my page layout.

The author names are shown by embedding a separate view using a pivot table that contains a many-many relationship, but the View is now displaying with its own div ID. I can't seem to add classes to this DIV so I can display it inline, so now my formatting is completely thrown.

How can I set this up to show the View results inline again?

#350852

Thank you for contacting us here in the Support Forum

This is because since Views 1.1.11, the Views loop output is wrapped in some default HTML.
This HTML (div) will not allow to put Views Loop output inline with other content anymore.

Why this has been done?
To support new features of Views, such as infinite Scrolling as example.

Since Views was and is designed to create lists and displays of content, it is wrapping this content in HTML, to provide best support for all features.

What can you do to solve this?

You can apply a filter in your functions.php, which will remove this HTML wrapper and provide a "Results only" loop output.

Please acknowledge that it will also mean, features like:
- Pagination, specially AJAX pagination, will not work.
- Parametric search, specially AJAXed parametric search, will not work.
- Other future features will not work either (endless scroll, future feature "sort by" in the front end, etc)

What does the filter do:
- It hooks early in the View output.
- Priority 5 is mandatory as we already do some other cleaning at priority 10.
- 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.

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' ) { //Adjust 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;
}

Please let me know if the above solution works for you, I look forward to your reply!

Thank you for your patience.

#350856

Hi Beda

Thank you very much - that works perfectly! Will this work with a comma delineated list for multiple IDs? And what's the chance this can be built in as an option in a View's front end? Would make a big difference for cases like this application.

many thanks
Ian

#350864

I apologize, but I do not understand.

1. What's the chance this can be built in as an option in a View's front end?

This filter is applied from functions.php to the relevant View(s).

It affects the Loop output, therefore, what you see on your Front End.

2. Will this work with a comma delineated list for multiple IDs?

Sure, you (with the filter) just remove everything from (incl) <!-- wpv-loop-start --> to (incl) <!-- wpv-loop-end -->

So everything you have in the Loop is still returned/output.

Thank you

#350866

Hi Beda

Sorry - I was meaning - can one have multiple view IDs listed in the filter I've added to functions.php - e.g.:

add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );
function prefix_clean_view_output( $out, $id ) {
if ( $id == '2812,2876,3445' ) { //Adjust ID...?

{I really must learn some proper PHP!}

...and then, would it be possible at some point to add a tick box in the View front end (in advanced options, perhaps) to remove all the HTML without going this route of adding a filter to functions.php?

Thanks

#350894

Ah, yes, sure.

You need a Array in this case.

Excluding ID's

$exclude_ids = array( 123, 456, 789 ); //SET YOUR EXCLUDING IDS HERE
    if ( ! in_array( $view_id, $exclude_ids ) {
...
}

Including

if (in_array($view_id, array(12, 13, 14) ) )  { //set your View ID's here
...
}

See a full solution here:
https://toolset.com/forums/topic/views-result-array-as-shortcode-parameter/page/3/#post-345598

This will always be needed to be applied in Functions.

Future Views features will include a GUI option to deploy raw View output, but this is under development.

Please do not hesitate to open a new thread if other issues or problems arise

Thank you

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.