• Resolved annafjmorris

    (@annafjmorris)


    Hi I am trying to make a blank custom template so I can make a diffrent design for a particular page type. My theme is 2020, but for some pages I want a very slimmed down theme with just a plain background, no menu etc.

    What I have done so far:

    – made a text file called vignette-template.php
    – saved it in 2020 child (there are only two other files there, functions.php and style.css)
    – put in the php I found on a forum (https://www.cryoutcreations.eu/forums/t/blank-page-template) and edited the info. The code is now:

    <?php
    /**
     * The main template file
     *
     * This is the most generic template file in a WordPress theme
     * and one of the two required files for a theme (the other being style.css).
     * It is used to display a page when nothing more specific matches a query.
     * E.g., it puts together the home page when no home.php file exists.
     *
     * @link https://developer.www.ads-software.com/themes/basics/template-hierarchy/
     *
     * @package WordPress
     * @subpackage Twenty_Twenty
     * @since Twenty Twenty 1.0
     */
    
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php the_content(); ?>
    <?php endwhile; ?>
    <?php endif; ?>

    Problem:

    It’s not appearing in the page attributes > templates section as expected though – not sure if thats bad php or something else.

    I looked at “WordPress template hierarchy” but didn’t really understand how to act on the info there.

    I’m very new at this level of development work and my understanding of php and things isn’t great. but I’m keen to learn! I

Viewing 5 replies - 1 through 5 (of 5 total)
  • To have it appear in your Page Attributes metabox, you need to use a comment like this: <?php /* Template Name: Vignette */ ?>

    https://developer.www.ads-software.com/themes/template-files-section/page-template-files/#creating-custom-page-templates-for-global-use

    Thread Starter annafjmorris

    (@annafjmorris)

    Hi

    Thanks, I have now tried this and read the documentation signposted (which was really helpful, so I bookmarked it!) however I still can’t get it working.

    Here is my file now:

    <?php /* Template Name: Vignette */ ?>
    <?php
    /**
     * The main template file
     *
     * This is the most generic template file in a WordPress theme
     * and one of the two required files for a theme (the other being style.css).
     * It is used to display a page when nothing more specific matches a query.
     * E.g., it puts together the home page when no home.php file exists.
     *
     * @link https://developer.www.ads-software.com/themes/basics/template-hierarchy/
     *
     * @package WordPress
     * @subpackage Twenty_Twenty
     * @since Twenty Twenty 1.0
     */
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php the_content(); ?>
    <?php endwhile; ?>
    <?php endif; ?>

    I tried the comment:

    at the top
    before <?php if (have_posts etc
    at the end

    I have tried putting the file in:

    twentytwenty / templates
    twentytwenty / template-parts
    twentytwenty-child
    twentytwenty-child [then added folder] /templates [and put it in there]

    Still not showing up

    I’d appreciate any help or advice you can give, thanks

    Anna

    Thread Starter annafjmorris

    (@annafjmorris)

    Hi, bumping this – keen to get help and learn how to do it. Hoping to write a how-too-guide on my blog from what I learn.

    Thread Starter annafjmorris

    (@annafjmorris)

    Hi, okay I have solved this – A friend pointed out that I had an extra php opening tag.

    now my code is :

    <?php /* Template Name: Vignette */ 
    /**
     * The main template file
     *
     * This is the most generic template file in a WordPress theme
     * and one of the two required files for a theme (the other being style.css).
     * It is used to display a page when nothing more specific matches a query.
     * E.g., it puts together the home page when no home.php file exists.
     *
     * @link https://developer.www.ads-software.com/themes/basics/template-hierarchy/
     *
     * @package WordPress
     * @subpackage Twenty_Twenty
     * @since Twenty Twenty 1.0
     */ ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php the_content(); ?>
    <?php endwhile; ?>
    <?php endif; ?>

    and it shows up under page templates (not post templates)

    final file location was

    twentytwenty-child [then added folder] /templates [and put it in there]

    Thread Starter annafjmorris

    (@annafjmorris)

    I also added in

    <?php 
    get_header();
    ?>
    
    <div id="primary" class="vignette">
      <div id="content" role="main">

    to let me theme with CSS

    so now I have

    <?php /* Template Name: Vignette */ 
    /**
     * The main template file
     *
     * This is the most generic template file in a WordPress theme
     * and one of the two required files for a theme (the other being style.css).
     * It is used to display a page when nothing more specific matches a query.
     * E.g., it puts together the home page when no home.php file exists.
     *
     * @link https://developer.www.ads-software.com/themes/basics/template-hierarchy/
     *
     * @package WordPress
     * @subpackage Twenty_Twenty
     * @since Twenty Twenty 1.0
     */ ?>
    <?php 
    get_header();
    ?>
    
    <div id="primary" class="vignette">
      <div id="content" role="main">
    
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php the_content(); ?>
    <?php endwhile; ?>
    <?php endif; ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Stuck making custom template (for 2020 theme)’ is closed to new replies.