Php 自定义贴子页面模板

Php 自定义贴子页面模板,php,wordpress,Php,Wordpress,我有一个问题,这个脚本应该加载一个自定义模板时,查看自定义文章页面 我放置了一个echo命令来确保url是正确的,但我甚至没有回显url function da_custom_post_type_template($single_template) { global $post; if ($post->post_type == 'include') { $single_template = PLUGIN_PATH. 'template/custo

我有一个问题,这个脚本应该加载一个自定义模板时,查看自定义文章页面

我放置了一个echo命令来确保url是正确的,但我甚至没有回显url

function da_custom_post_type_template($single_template) {
     global $post;

     if ($post->post_type == 'include') {

          $single_template = PLUGIN_PATH. 'template/custom_template.php';
     }
     echo $single_template;
     return $single_template;
}
add_filter( "single_template", "da_custom_post_type_template" ) ;

请帮助将其放入single.php中:

<?php
      global $wp_query;

      $post = $wp_query->post;
      $post_type = get_query_var('post_type');

      if($post_type == 'include'){
        include(TEMPLATEPATH.'/my_post_template.php');
      }else{
        include(TEMPLATEPATH.'/default_post_template.php');
      }#end else

?>

实际上,您仍然可以过滤单个模板。它仍然存在于
wp includes/template.php

我看不出你的功能有什么问题。您确定模板文件存在吗

编辑:

试试这个:

function da_custom_post_type_template( $template ) {
    global $post;

    if ($post->post_type == 'include') {
        $template = dirnamr( __FILE__ ) . '/template/custom_template.php';
    }
    return locate_template( $template );
}
add_filter( "single_template", "da_custom_post_type_template" ) ;
终于做到了

我重新下载了wordpress并将我的代码更改为以下

gobal$post似乎没有任何设置,所以我使用$wp_查询。谢谢CroiOS指出这一点

同时也感谢CMF为我在word press问题上的安装指明了正确的方向。我通过SSH安装了WP,所以我想知道我是否下载了夜间构建之类的东西

function da_custom_post_type_template( $template ) {
    global $wp_query;
    if ($wp_query->post->post_type == 'include') {
      $template = PLUGIN_PATH . '/template/custom_template.php';
    }
    return $template ;
}
add_filter( "archive_template", "da_custom_post_type_template" ) ;

出于某种原因,它的类作为存档模板:)

尝试回显“test”;检查是否有回声。。。我们将知道它在函数内不,它看不到在函数内的回声(@DavidAllen您如何将$single_模板传递给您的方法???)不,我只是在处理这个问题,只是尝试了一下,没有,但仍然无法工作…:(我正在制作一个插件,所以我不能这么做。我的wp includes文件夹中没有template.php。我已经重新下载了wordpress,现在有一个template.php