This is a strange task but I really faced with it. On the home page there is loop for showing all custom post type. And I need to have oportunity when user click to the cpt link from the home page display one type of the single page. And if user go to the custom post type from inner page show other single custom post type template. I found old answer about this on the stackoverflow But it does not work properly. The code from stackoverflow:
On the home page I added to the link something like this:
<a href="<php the_permalink();?>?template=gallery"> Gallery Page </a>
And in the custom post type single page add this chunk of code:
if($_POST['template'] == 'gallery') {
get_template_part('single', 'gallery'); // the file for this one is single-gallery.php
}elseif($_POST['template'] == 'other'){
get_template_part('single', 'other'); // the file for this one is single-other.php
}
At first glance, this makes sense, but it doesn't work. Please help to solve this.