doudouba4520 2019-06-07 15:05
浏览 248
已采纳

如何获取页面模板名称? 例如 模板名称:模板名称

Is there any way to get the name of the page template?
I mean in a page template, at the beginning we write Template Name: template name
I want "template name" by page-id

I've tried get_post_meta(get_the_ID(), '_wp_page_template', true) and get_page_template_slug($post_id) but none of the function helped

  • 写回答

2条回答 默认 最新

  • dongzang5815 2019-06-10 16:37
    关注

    I have figured it out.
    As I'm going to use inside WordPress admin I've used regular expression.
    It's something like this preg_match('/\bTemplate Name: [a-zA-Z0-9\s\-_]+\b/',$file,$template);.
    $file is the file name from get_post_meta(get_the_ID(), '_wp_page_template', true)

    It gives me Template Name: template name and then I used some array functions to get an actual part from returned array from preg_match.

    I hope this solution will help other developers in future.

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

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办