1

My problem:

I have a custom page format for events. Now I would like to get different outputs for each of these events.

  1. Normal webpage › for visitors
  2. Custom look › for easy copy and paste to other platforms for seminars.

My question

Is it possible to design two templates with different URLs. So that I have the possibility to call these pages with custom templates/designs?

1 Answer 1

1

Query string parameters are a helpful friend in this situation. It will allow you to keep the same single-$posttype.php file for both formats of the page.

So if someone visits your page using the URL:
https://yourwebsite.com/events
They will see your normal webpage for visitors. But if someone uses the URL:
https://yourwebsite.com/events?seminar=true
They will see something completely different.

This is accomplished by using the $_GET global variable provided by PHP. Documentation is here.

So you could do the following using a single-event.php page (providing event is a post type):

<?php
$is_seminar = $_GET['seminar'];

if ( $is_seminar === 'true' ) : ?>
  <h1>Custom look for seminars.</h1>
<?php else : ?>
  <h1>Normal webpage</h1>
<?php endif;

Or if you want a little bit of a cleaner look to your URL, take a look at Get URL query string parameters using $_SERVER['QUERY_STRING']. Also see How can I make different page templates for one category? for another alternative solution using your post's meta info.

1
  • Hey @Dcfunkster – Thank you very much for your help. I tried your solution. It works ;)
    – Phlow
    Commented Feb 21, 2023 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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