duan198299 2019-06-25 18:36
浏览 96

Wordpress:在获取模板时,零件未显示

I'm trying to redirect some of my posts from Single.php template to my training-v2 custom template using the code below, but the get_template_part is not working.

My templates are in the order of

themes/theme/templates/training-v2.php

themes/theme/single.php

Can anyone help with the get_template_part structure?

<?php
if (have_posts()) : while (have_posts()) : the_post();

    $custom_arr = array(6647,6794,6796);
    if (in_array(get_the_ID(), $custom_arr)) {
        get_template_part( 'themes/theme/templates', 'training-v2' );
    }
    else {
       get_template_part( 'theme/content', 'single' ); 
    }

endwhile; else :

    get_template_part( 'parts/content', 'index' );

endif;
?>
  • 写回答

1条回答 默认 最新

  • drwurqczo39355510 2019-06-25 18:58
    关注

    Presuming the path you said (that's www.example.com/wp-content/themes/theme/ for your theme root), it must be:

    get_template_part( 'templates/training', 'v2' );
    

    Codex wordpress get_template_part

    First parameter is the path from your theme root and the second parameter is for versioning this. The second is optional. A footer or header is a great example why you need different versioning of the file. Allows a better templating structure.

    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据