Nakul Bharat
Nakul Bharat

Reputation: 25

Wordpress Page Template Issue: Cannot see my Custom Page Template in page attribute dropdown

I am using Understrap to develop a custom theme and when I add a new page template, it does not show up on the page attributes dropdown. These are the fixes I have tried and they don't work: 1) Activating to another theme and changing back to Understrap. 2) Using a plugin to clear cache due to the caching issue of wordpress 4.9. 3) Bumping Theme Version. 4) Updating Wordpress.

Nothing Seems to work and I am in a fix!.

I am using MAMP for local dev.

folder structure

page templates folder, I've highlighted the files that I have added, none of them show on the dropdown

Thank you for any help that you can provide and please do let me know if you need more info.

EDIT:

<?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(); ?>

This is the template that I want to Include.

EDIT 2: As @Alexander Suggested I included that code in the functions.php. It Didn't work..I then included a small snippet to display the page template array on the index page and modified the code snippet like so.

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

}

This is the result:loop and array

Upvotes: 1

Views: 3288

Answers (3)

Nakul Bharat
Nakul Bharat

Reputation: 25

OK I have found the problem, it was quite silly, There is space between name and :, well it shouldn't be there. Thank you for all your answers and suggestions.

Upvotes: 0

Patrick R
Patrick R

Reputation: 6857

It seems like space issue. Can you make only below change in your custom template file:

From

Template Name : Portfolio Page Template

To

Template Name: Portfolio Page Template

I checked the same in my local set up and confirmed above. It will work for you.

Upvotes: 2

Alexander Z
Alexander Z

Reputation: 604

On the one hand, You need to adhere to the file structure that is adopted in Wordpress. So, page templates must been putted in the root folder of theme or child theme.

But also there is always another way, you can include the file in functions.php:

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

Upvotes: 0

Related Questions