最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

WordPress different templates for same type custom post (but different slug)

programmeradmin0浏览0评论

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.

Share Improve this question edited Jan 17, 2021 at 5:50 Dev asked Jan 16, 2021 at 19:07 DevDev 1012 bronze badges 4
  • 1 I'm sorry but most of the normal solutions will work for you since you are using the Pods plugin. Additionally, your directors and actors should not be the same post type if you intend them to behave differently. You need Pods help, not WordPress help – Tom J Nowell Commented Jan 16, 2021 at 19:35
  • I'd attempt to tackle this in a single template and just change the output based on the slug, but that's IF I hadn't already made them different post types as Tom J. Nowell suggested, however, I know next to nothing about pods. Is it too late to separate the post types? – Tony Djukic Commented Jan 16, 2021 at 20:43
  • @TomJNowell there should be some solutions from WordPress. What if I'm not using pod then same scenario. – Dev Commented Jan 17, 2021 at 5:52
  • All the solutions I can think of involve changing 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 to register_post_type and abandon pods – Tom J Nowell Commented Jan 17, 2021 at 10:43
Add a comment  | 

1 Answer 1

Reset to default 1

In 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>
发布评论

评论列表(0)

  1. 暂无评论