If the content does not change you could surly do this with CSS. The fact that in the grid view the content itself will be different,if even slightly, means you will need to alter the loop or make a new one.
I would suggest having a look at get_template_part
, this and this to see how you could use get_template_part
.
So just have an event listener on the button that changes the view and according to that value serve a template part for the view. This means you will most likely want to do this with AJAX or API calls to not reload the entire page but just the changing template.
I would refrain from adding parameters to the url, unless you need the grid view linkable, meaning someone that enters the site on that link and not on the index page will have that view.
Last thing, does changing of the layout per user enhance the experience or usability of the site?
Related Posts:
- Solutions for generating dynamic javascript / CSS
- Custom single template for a specific category
- Import media to online WordPress from local development
- How to add a checkbox element to attachments editor with example
- Auto get_header and get_footer on every template?
- Nested comments ignored for max per page in wordpress
- Theme Check gives: Required: This theme doesn’t seem to display tags?
- Is it possible to use line break in theme description?
- How does WordPress decide what template to use as frontpage
- get_option function
- Twenty Eleven home page show only excerpt
- Override Current Theme Setting in wp_config.php
- How do I “unhook” / de-register jQuery so that it’s not called as part of wp_footer();?
- Set Expiration Date of a Post from the Frontend with wp_insert_post
- WP Gutenberg custom block – generate theme colors from SASS and use them in the inspector and php callback
- Resources for a complete beginner to learn to work professionally with WordPress [closed]
- “Cheatin’ uh?” error message on multple theme directories
- How to tell if the user is an admin?
- Is tag default in WordPress?
- “Display Site Title and Tagline” checkbox not working?
- Getting jquery to work with custom theme
- How to retrieve an image from a post and display it before excerpt of a post? [duplicate]
- Why does WP recommend against custom favicon functionality in themes?
- Excluding a page with a certain name from wp_page_menu
- Widgets with groups / sub widgets? Widget in a widget?
- Why is the first query affecting the second query, even after wp_reset_query() and wp_reset_postdata(), but not on the second page?
- Avada resources still loading from localhost after database migration [closed]
- No Appearance –> Header menu
- Add theme templates for child categories into the template hierarchy
- How do I create a custom partial / template?
- Internationalization and functions that use it
- How should I be handling my theme version numbering?
- How to make Isotope and WordPress work together?
- WordPress empty Nav Menu error
- How do I Add images uploaded in the post to a default custom field
- Update Custom Theme Version
- Storefront child theme not applying parent theme [closed]
- What can I use for small text when converting to WordPress?
- How to specify the “Main Sidebar” for a theme
- How to place HTML tags in content from the_content()?
- Can I get the ID of an inserted / linked image?
- Integrate WooCommerce theme with a WordPress theme [closed]
- Automated Footer information
- How do you use WordPress for a website that’s not in a blog format?
- Custom theme, contact form 7 & fast secure form doesn’t work
- How to develop a menu like wwe.com?
- Add tags to pages
- Why set a second parameter in the translate function?
- do_shortcode() in twentyeleven theme
- Override plugin option by with a custom theme
- Replace site title with logo when logo is uploaded in customizer using
- Review site using WordPress
- How to create query to get top 3 sticky/latest posts
- Fatal error: Class ‘ZipArchive’ not found
- Is it possible to determine when user is at “Media > Add New” vs “Post > Add an Image”
- Running a function on post update with new post meta
- Check if( selected() )
- Modify available templates (in dropdown)
- Difference between “comment_form_default_fields” AND “comment_form_fields”
- using custom page
- Clearing dummy data before launch
- Multiple editable areas
- Create new wordpress theme with no need update
- How to display date of blog creation
- Add image URL automatically to custom field?
- content filter (add_filter) for category description?
- Theming media inserts
- How to update mark-up of a gallery block in a custom theme?
- wordpress script_loader_tag in function.php
- Host Private Custom Theme
- Why not works the search.php file?
- My wordpress theme name isn’t updating straight away
- How do I make my terms for each product display via foreach loop? (woocommerce)
- WordPress Insert ads after every 5th post
- How to get custom logo with REST API instead of get_theme_mod();
- How can I change this SVG shape that’s generated?
- Theme starter content translation is not working
- Adding a second logo next to the main one in header
- (Parent) theme Is Not Showing In Theme Selection Panel and Therefore Breaks Child Theme
- How to add an image to a theme page template in code?
- Looking to create an “update theme” functionality for a custom front-end dashboard
- remove_action(‘genesis_header’,’genesis_do_header’) hook not working
- Text View (Code View) in WordPress Customizer TinyMCE Editor
- Different stylesheet for different pages not working fully
- Can I use WP Multi-site on a sub-domain with a different theme but use all the original site’s posts/pages?
- How to Apply Category Filter to Pagination
- How do I use the add_query_arg function in a template tag like previous_post_link?
- Get all Custom Post Types
- Let users to add any number of input fields in the theme option page
- wpalchemy repeating fields dropdown issue
- Does WordPress require that your submitted theme supports multiple menu levels?
- Add custom field to existing meta box?
- Standard Way To Do Custom Work Within A Page?
- Subsite theme mystery man replacement with Buddypress on main site [closed]
- Add Dynamic Sidebar to Exisiting WordPress Theme [closed]
- Why does the first loop take arguments from the second loop?
- Theme layout for home page [closed]
- Is there any reason that other theme elements (such as nav menus) shouldn’t be within the loop?
- Is there any way to show child theme in theme detectors?
- Meaning of “if ( is_home() && ! is_front_page() )” snippet?