How can I dynamically load another page template to provide an alternate layout of the posts?

I think I have a workable solution on what I was trying to do. This works but is there a better way? Also are there any implications I should be aware of when using $_GET? Didn’t realize it would be this easy 🙂 perhaps I’m missing something.

<?php $view = $_GET["view"]; ?>

Then if the URL is domain.com/page/?view=list I use an IF statement inside the loop to modify the markup as required:

<?php if ( $view == "list" ) : ?>

    // code here for list view

<?php else : ?>

    // code here for normal default view

<?php endif; ?>

Leave a Comment