【问题标题】:Wordpress single post file not found找不到 Wordpress 单个帖子文件
【发布时间】:2016-09-05 22:22:35
【问题描述】:

我正在开发一个显示投资组合的插件。 我添加了一个自定义帖子类型功能,但是当我转到单个页面时,它不会识别 single-portfolio.php。

我试过的是:

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

我的 single-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

谢谢, 伦斯·曼德斯

【问题讨论】:

  • 空白页或 404 页面出现什么错误..
  • 使用的是主题本身的single.php文件,好像看不到single-portfolio.php文件
  • 试试这样 隐藏single-portfolio.php 那里并创建您的自定义文件并检查页面是否打开。让我知道
  • 当我从主题中隐藏 single.php 文件时,它没有样式,并且仍然无法识别插件的 single-portfolio.php 文件。
  • 如果您在插件下工作,您需要单独完全控制插件。不要打扰他们在主题中编写的功能。

标签: php wordpress plugins


【解决方案1】:

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

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

如果这将是您计划发布的插件,我会考虑从插件目录加载,同时仍然为用户提供从他们的主题覆盖的选项。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多