1

I have a live website that is using the custom post type "virtual-programs" and I have a template that currently works called single-virtual-program.twig and single-virtual-program.php.

I am developing new templates (single-virtual-program-new.twig and single-virtual-program-new.php)

They will eventually replace (single-virtual-program.twig and single-virtual-program.php)

During development I want to have both templates active, then once I'm happy with it, I will activate the new templates and remove the the old templates.

To do this I will need to create custom URLs for my NEW templates so I can view them while the old templates are still live. How do I go about that?

FYI I'm using Timber (.twig).

Here is the code from single-virtual-program.php

$post = Timber::query_post();
$context['post'] = $post;
$context['archive_link'] = get_site_url(null, str_replace('_', '-', $post->post_type));

$context['virtual_programs'] = Timber::get_posts(
  array(
    'post_type'       => array('virtual_programs'),
    'post__not_in'    => array($post->ID),
    'posts_per_page'  => 5,
    'meta_query'      => array(
        array(
            'key'     => 'event_type',
            'value'   => array('online', 'Online Short Course'),
            'compare' => 'NOT IN'
        )
      )
  )
);

$context["register_event_url"] = get_field("prices", $post->ID)[0]["register_link"];


Timber::render( 'single-virtual-programs-new.twig' , $context );

Thank you.

2
  • Why not create a staging site and test your new templates there without having to use the different names? Once ready, you'd then just need to replace the old theme on the live site.
    – Sally CJ
    Commented Aug 10, 2020 at 2:43
  • 1
    Thanks Sally, I do have a staging site and that's probably the best way. I might just create a new branch incase I need to make other changes to my site during development and then merge them once it goes live. Commented Aug 10, 2020 at 2:47

2 Answers 2

1

Template hierarchy allows you to be specific down to a post name. This then allows a method (which I have used) to test out a newer version of the template on one specific page.

See this page on WP

For example. If you create a virtual-program page called 'wpse372687', the file 'single-virtual-program-wpse372687.php' is more specific for that particular page. When you visit that page you use the new template, but any other virtual-program page uses the next best match of the old/current template.

It has its limits but its an easy way of testing side by side, if you don't want to go down the route of a staging server (which is also a good suggestion from Sally).

0

Ok, so the answer is simple and I forgot about it totally.

Just create a new template (single-virtual-program-new) and then in the single custom post, select the new template from the dropdown.

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.