Loading two post layouts for the same post with different url

How can I show the same post content with two different post layouts on two different URLs?

For example

https://www.domain.com/help-brothers/post-layout-1/post-name
https://www.domain.com/help-brothers/post-layout-2/post-name

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can pass the layout name as a GET parameter and then change the design based on that. So your URL should be something like this:

http://domain.com/post-name?layout=layout-1

Now in your single.php file or whatever file that renders the template, you can do this check to show the different layouts:

<?php 
// If the header is different two, you should call for different headers too, 
// Check this for showing different headers
// https://developer.wordpress.org/reference/functions/get_header/
if( isset( $_GET['layout'] )  && $_GET['layout'] == 'layout-1' ) {
    // Show the design for for the first layout 
}
else if ( ... ) {
    // Show the design for other layouts 
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x