I have created one custom post type lets say movie, now I have created 4 posts under movie type.
Slugs are movie/parasite/director
and movie/parasite/actor
.
Similarly movie/joker/director
and movie/joker/actor
. Now I want to load two types of template one for director and other for actor based on slug.
I'm using pod plugin for custom post type.
What I'm doing I have created one single php file name single-movie.php
file under theme folder. This single-movie.php
file template file is loading for all movie post type but I want to load different template based on movie post type slug. Any help appreciated.
I have created one custom post type lets say movie, now I have created 4 posts under movie type.
Slugs are movie/parasite/director
and movie/parasite/actor
.
Similarly movie/joker/director
and movie/joker/actor
. Now I want to load two types of template one for director and other for actor based on slug.
I'm using pod plugin for custom post type.
What I'm doing I have created one single php file name single-movie.php
file under theme folder. This single-movie.php
file template file is loading for all movie post type but I want to load different template based on movie post type slug. Any help appreciated.
1 Answer
Reset to default 1In this case, since there's a many-to-many relationship between movies and actors, I recommend making them two separate pods with a relationship between them. See the intro video at https://pods.io/ ... I don't remember where he explains relationship fields but it's all in there.
You don't need to use PHP if you don't want to. You could use Pods templates (see the video). Something like this for movies (it's a tweak of one of mine). It assumes you've filled in the title and content for both movies and actors:
<div>
[if related_actors]
<h4 style="font-weight:bold; font-size:x-large;">Actors:</h4>
<div style="padding-left:4em;">
[each related_actors]
<h3>
[if post_thumbnail_url]
<img src="{@post_thumbnail_url.small}" style="float:left; width:150px; height:auto; padding-right: 15px;">
[/if]
{@post_title}
</h3>
<div style="clear:both;">{@post_content}</div>
[/each]
</div>
[/if]
</div>
register_post_type
parameters which you don't use because you use Pods. Pods help and other 3rd party plugin dev support is off topic here. The only generic solution that might work is to admit that you actually have 2 post types not 1 and split them rather than trying to bundle them into one, or to move toregister_post_type
and abandon pods – Tom J Nowell ♦ Commented Jan 17, 2021 at 10:43