[Gelöst] Can you generate a view that has 2 loops?
This support ticket is created vor 5 Jahren. 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.
Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.
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
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.
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: versteckter Link
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
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.
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
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.
"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.
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.
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. 🙂
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?