Skip Navigation

[Resuelto] Can you generate a view that has 2 loops?

This support ticket is created hace 5 años. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Etiquetado: ,

Este tema contiene 14 respuestas, tiene 2 mensajes.

Última actualización por Francisco Ramón Molina Busquiel hace 4 años, 12 meses.

Asistido por: Nigel.

Autor
Mensajes
#1391147

Hi!
Can you generate a view that has 2 loops?
I want to do the following view:
* Manufacturer 1
** Printer 1
** Printer 2
** ....
* Manufacturer 2
** Printer 1
** Printer 2
** Printer 3
** ....
Thanks for your help.
Regards,
Jose

#1391363

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

Hi Jose

You cannot do that with a single View, you need two, nested, Views.

In your example, you would create an outer View to display Manufacturers.

The output section of that View will iterate over each Manufacturer. So in the output section insert a second View which queries Printers.

This inner View will need a Query Filter to only display Printers belonging to the current Manufacturer in the outer View.

The exact Query Filter you use will depend upon how your Manufacturer and Printer data are connected. If they are both post types, connected in a relationship, then you would insert a relationship filter.

If Manufacturer were a taxonomy the you would insert a taxonomy filter where the term was set by the parent View, for example.

Knowing your data, it should hopefully be clear which filter to insert, but let me know if you are stuck.

#1391469

Hi Nigel,
I have created 2 views:
Impresoras-Fabricante View
slug: impresoras-fabricante-view
Impresoras View 2
slug: impresoras-view-2
But I don't know how to create a filter to link them.
The printer type has a manufacturer related field, that field must be linked by the filter with the manufacturer's post id.
Another thing. How do you view printers in the manufacturer's loop?
The main view of manufacturers to show the double loop is on the page:
enlace oculto
Please, HELPPPPPPPPP!!!!!! 🙂
You can use the username and password that I indicated on the other ticket to login in the dashboard.
Thanks for your help Nigel.
Regards,
Jose

#1392129

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

Sorry Jose, the other thread is marked as resolved, and so the site credentials are automatically deleted for security.

Let me set up a private reply again now and I'll take a look.

#1392337

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

Screenshot 2019-11-26 at 11.53.20.png

The outer View queries and iterates over manufacturers.

In the output section of that View you insert an inner View, to output printers belonging to the current manufacturer.

I've done that on your site, inserted the inner View in the output section of your outer View.

I modified the Query Filter of the inner View (see screenshot).

Your printers are connected to manufacturers by a post relationship field, which are implemented as relationships, so you can add a relationship filter.

The results are functional, but pretty messy. I'll leave you to work on that.

#1392351

Nigel, thank you very much, I have already understood, however, something curious happens, if you place yourself on page number 1, and click on 'siguiente' the whole page scrolls to the end, and so on. This is normal?
Thanks for your help.
Regards,
Jose

#1392401

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

I wouldn't say it is normal, but I might say it is expected.

Playing around with navigating between different pages, and trying the same when temporarily disabling the nested View, I think I can see why it is happening.

You have included the pagination after the results.

If you just have the outer View and no inner View, the number of results—and the length of the results—is the same on each page. When you navigate from one page to another it scrolls to keep you in the same position after the results are updated.

But when you enable your nested View, the length of the results can be very different from one page to the next. If you are on a page with a long list of results and you then navigate to a page with many fewer results then when it scrolls to where it thinks the end of the results would be (based upon the last page) then it is going to scroll too far, taking you down to the footer and even the very bottom of the page.

I don't see any way around this with your current set-up.

You could resolve the problem by disabling ajax for the pagination and using a page reload (which would, I think, give a better result of starting at the top of the results).

Or, I think if you added the pagination above the results, to the Search and Pagination editor, you wouldn't have the same problem.

#1392447

"Or, I think if you added the pagination above the results, to the Search and Pagination editor, you wouldn't have the same problem."

I don't know exactly where to place the code regarding your directions.

"You could resolve the problem by disabling ajax for the pagination and using a page reload (which would, I think, give a better result of starting at the top of the results)."

At the moment, I have disabled AJAX and that gives a better feeling.

Regards,
Nigel

#1392479

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

Just cut and paste the markup and shortcodes for the pagination you have in the Loop Editor into the Search and Pagination section, somewhere before the wpv-filter-end shortcode.

Try that with ajax. I think the result will be better, but I'm not sure.

#1392491

I have done. It works best, although the user has to be at the top of the list every time he wants to change the page.
You should have a mode that was an automatic scroll just like twitter or other pages do. It would be fabulous. 🙂

#1393005

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

Twitter uses infinite scroll, is that what you mean?

You can do that with Views: https://toolset.com/documentation/user-guides/infinite-scrolling-in-views/

#1393169

Thank you very much Nigel. I will try it.

Regards,

#1393975

Nigel, One question, I turn to your wisdom. 🙂
In the view loop can I put some shortcode to show a header on each page?

Thanks for your help.

Regards,

#1393977

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

No, it's too late.

WordPress builds the page in sequence.

By the time it finds a View in the content, the header has already been assembled.

If you want to add something to the header you would either need to edit the header.php file of the theme or use a WordPress API hook to inject something.

If you have questions about that, could you please open a new thread?

Thanks

#1394125

Thanks for everything Nigel.