Wordpress页面模板问题:在页面属性下拉列表中看不到我的自定义页面模板

时间:2018-02-09 09:48:40

标签: wordpress

我正在使用Understrap开发自定义主题,当我添加新的页面模板时,它不会显示在页面属性下拉列表中。 这些是我尝试过的修复程序,它们不起作用: 1)激活另一个主题并更改回Understrap。 2)由于wordpress 4.9的缓存问题,使用插件清除缓存。 3)颠簸主题版。 4)更新Wordpress。

没什么似乎工作,我正在修复!。

我正在将MAMP用于本地开发。

beginPage(withBounds:pageInfo:)

folder structure

感谢您提供任何帮助,如果您需要更多信息,请告诉我们。

编辑:

<?php
/**
 * Template Name : Portfolio Page Template
 *
 * template for the portfolio masonry style
 *
 * @package understrap
 */

get_header();
$container = get_theme_mod( 'understrap_container_type' );
?>
<div class="wrapper" id="full-width-page-wrapper">
<div class="<?php echo esc_attr( $container ); ?>" id="content">

<div class="row">

<div class="col-md-12 content-area" id="primary">

    <main class="site-main" id="main" role="main">


        <?php echo '<div class="card-deck">' ?>
        <?php 
        $args = array( 'post_type' => 'portfolio', 'posts_per_page' => -1);
        $loop = new WP_Query( $args );
        while ( $loop->have_posts() ) : $loop->the_post(); 
        ?>
        <div class="card">
        <a href = " <?php print get_permalink($post->ID) ?> "><img class="card-img-top" src="<?php get_post_thumbnail_url($post->ID); ?>" alt=" "></a>
        <div class="card-block">
        <h4 class="card-title"><?php print get_the_title(); ?></h4>
        <p class="card-text"><?php print get_the_excerpt(); ?></p>
        </div><!--card-block-->
        <div class="card-footer">
        <small class="text-muted"><?php get_the_terms($post->ID, array( 'Skills' )); ?></div>
        </div>
        </div><!--card-->
            <?php endwhile; ?>
        </div><!--#card-deck-->

    </main><!-- #main -->

</div><!-- #primary -->

</div><!-- .row end -->

</div><!-- Container end -->

</div><!-- Wrapper end -->
<?php get_footer(); ?>

这是我想要包含的模板。

编辑2: 正如@Alexander建议我在functions.php中包含该代码。它没有工作..我随后包含一个小片段,在索引页面上显示页面模板数组,并修改了代码片段。

if( is_page_template( 'page-templates/page-portfolio.php' )){
echo "template exists";
}
else{
echo "this template does not exist";

}

结果如下:page templates folder, I've highlighted the files that I have added, none of them show on the dropdown

3 个答案:

答案 0 :(得分:1)

好像空间问题。您是否可以在自定义模板文件中进行以下更改:

Template Name : Portfolio Page Template

Template Name: Portfolio Page Template

我在本地设置中检查了相同内容并在上面确认。它会对你有用。

答案 1 :(得分:0)

一方面,您需要遵守Wordpress中采用的文件结构。 因此,页面模板必须放在主题或子主题的根文件夹中。

但也有另一种方法,你可以在 functions.php 中包含该文件:

if ( is_page_template( 'page-templates/my-template.php' ) ) {
  include_once 'page-templates/my-template.php';
}

答案 2 :(得分:0)

好的我发现了问题,这很傻,名字和:之间有空间,好吧它不应该存在。感谢您的所有答案和建议。