For a project of mine I need to define an alternative template for single posts. To be more specific I need each post to be displayed as usual when the website is browsed but I need to create different single pages reachable from different URL to create a sort of a mini-website for each post.

(I'm actually using the WooCommerce plugin and what I need to do is to create a mini-website for each product. This needs to be something "outside" from the main website, with a complete different graphic template and is going to be reachable through a QR-code).

Hope it makes a bit of sense. Thanks for your advices and/or suggestions. Angelo


You could set a url parameter to change the display so that the URL could be the same, then have your QR code do a pass-through to the desired page. Without knowing how the QR codes are setup and such, I can't offer much more on high-level implementation than that. The way to switch the templates would be as follows:

if( get_query_var( 'from_qr' ) == true )
    get_template_part( 'qr', 'single' );
    get_template_part( 'loop', 'single' );

You may want to use $_GET instead of get_query_var(), and you can structure that differently (I like get_template_part() because it makes the code easier to read and enhances my focus on SoC), but that's the general idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.