dongtui4038 2015-10-23 12:03
浏览 25
已采纳

单个自定义帖子类型的多个模板

I am developing a site for a company and I require the ability to have multiple template files for one custom post type. I have three landing pages that all display the same list of services/custom post type posts in a different manner; however, depending on the page the user is on, I want the inner template to change.

For instance, if the user is on the Gallery landing page and they click on the custom post type, I want the single-gallery template to be loaded. If the user is on the Testimonial landing page I want the single-testimonial template to be loaded and so on...

I have searched through WordPress and have found things like template_part and endpoints, but as a new user of WordPress I am in need of a bit more help!

Any help would be much appreciated. Thanks!

  • 写回答

2条回答 默认 最新

  • dsajkdadsa14222 2015-10-23 14:23
    关注

    For a quick solution I would suggest something like this:

    When linking you could use:

    <a href="<php the_permalink();?>?template=gallery"> Gallery Page </a>
    

    Then on the single-customposttype.php

    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
    }
    

    not the prettiest, but it's quick and easy to roll out.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂