[Resolved] How to display a different View on mobile devices?
This thread is resolved. Here is a description of the problem and solution.
Problem:
Client wants to display a different View on mobile devices.
Solution:
WordPress contains a built-in function wp_ismobile() that can be used in conditional shortcodes to determine which View is inserted depending on the device.
I am using Toolset views to create a gallery of images that link to individual entries.
I have set up 3 separate views for each gallery so that I can display a different amount of images depending on the device.
15 for desktop
12 for tablet
9 for mobile
I then use css to hide or show the appropriate gallery in the front end.
My question is... is my site generating all 3 views every time the user browses to a page? If so that seems like a very inefficient way to do things as my server needs to work 3 times as hard and takes 3 times longer to generate the page.
I read several posts where in which it was said that this should not effect page load time - but I don't see how that can be the case as the server needs to make 3 times as many requests etc.
Is this the proper way to handle various screen sizes?
You are right. Simply hiding the alternative galleries with CSS means they are *all* downloaded, making this a much worse solution in performance terms than just including a single gallery for all devices.
You need to make the decision *before* the page is rendered.
So where you insert these Views you can use conditional shortcodes and first check what device information you have to decide whether to display the particular gallery or not.