2016-09-05 27 views
0

我正在制作一个显示投资组合的插件。 我已经添加了一个自定义帖子类型函数,但是当我转到单个页面时,它不会识别single-portfolio.php。未找到Wordpress单帖文件

我已经试过是:

if(post_type == 'portfolio') 
    { 
     if(is_single()) 
     { 
      include('single-portfolio.php'); 
     } 
    } 

我的单portfolio.php代码:

<?php get_header(); ?> 

<?php 
if(have_posts()): 
    while(have_posts()): the_post(); 
     the_title(); 
     if(has_post_thumbnail()): 
      the_post_thumbnail('thumbnail'); 
     endif; 
?> 
     <?php $site= get_post_custom_values('projLink'); 
      if($site[0] != ""){ 
     ?> 
      <p><a href="<?=$site[0]?>">Live Preview</a></p> 

     <?php }else{ ?> 
      <p><em>Live link not available</em></p> 
     <?php } 
    endwhile; 
endif; 
?> 

<?php get_sidebar(); ?> 

<?php get_footer(); ?> 

我的插件结构:

devplugin\devplugin.php 
devplugin\posttype.php 
devplugin\template.php 
devplugin\addtemplate.php 
devplugin\single-portfolio.php 
devplugin\devplugin.css 
devplugin\css\bootstrap.min.css 

感谢, 伦斯·曼德斯

+0

什么错误显示出空白页面或404页面 –

+0

它使用主题本身的single.php文件,它看起来像他不能看到single-portfolio.php文件 –

+0

有一个这样的尝试隐藏那里的'single-portfolio.php'并创建你的自定义文件并检查页面是否打开。并让我知道 –

回答

0

您的single-portfolio.php文件位于您插件的目录中。 WordPress不会在那里寻找模板文件。

您需要将其放入主题文件夹或使用过滤器添加您的插件,因为可以从中加载一个目录模板。

如果这将是一个你打算发布的插件,我会考虑从插件目录加载,同时仍然允许用户从他们的主题覆盖选项。