0

I'm a newbie in English, and in creating my own WordPress theme. So I need your help.

I used Underscores, to help me create my own theme. And I have a problem with my templates:

Underscores use, for example, page.php with a part of the code in the file called template-parts.

The code for page.php is

<div id="template-right-sidebar" class="content-area">
        <?php
        while ( have_posts() ) : the_post();
            get_template_part( 'template-parts/content', 'page' );

            // If comments are open or we have at least one comment, load up the comment template.
            if ( comments_open() || get_comments_number() ) :
                comments_template();
            endif;

        endwhile; // End of the loop.

</div><!-- #template-right-sidebar -->

And the code of content-page.php in the template-parts file is :

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

<header class="entry-header">
    <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
</header><!-- .entry-header -->

<div class="entry-content">
    <?php
        the_content();

        wp_link_pages( array(
            'before' => '<div class="page-links">' . esc_html__( 'Pages:', '_-julie-cottet-web' ),
            'after'  => '</div>',
        ) );
    ?>
</div><!-- .entry-content -->

<?php get_sidebar();?>

<?php if ( get_edit_post_link() ) : ?>
    <footer class="entry-footer"></footer><!-- .entry-footer -->
<?php endif; ?>

</article><!-- #post-<?php the_ID(); ?> -->

(Ok, there is more code in reality, but I wanted to make my question more simple.)

The thing is I don't wan't to use the file template-parts. So I want to "copy" the code which is in content-page.php directly in page.php

I must to it wrong, because it is not working. And I don't know why...

What I did :

    <div id="template-right-sidebar" class="content-area">
    <?php
    while ( have_posts() ) : the_post();?>

        <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

             // AND ALL THE REST OF THE CODE 

         </article><!-- #post-<?php the_ID(); ?> -->

        <?php // If comments are open or we have at least one comment, load up the comment template.
        if ( comments_open() || get_comments_number() ) :
            comments_template();
        endif;

     endwhile; // End of the loop.

        </div><!-- #template-right-sidebar -->

What is my mistake ? How can I do that ?

Thanks for reading and for your help !

1

First of all a simple advice if you are a complete beginner: i suggest you start from scratch with a tutorial that step by step takes you to create a theme. That way you will have a better understanding on how it works. Underscores is great i use it my self but if you are a total newbie, it could be more difficult to start with.

Do you have WP_DEBUG set to true in your wp-config.php file? If not go on the main directory of you Wordpress install and add

define('WP_DEBUG', true);

It will allow you to see errors and help you identify what is the problem. Here i reproduced my working page.php using Underscores

<?php
/**
 * The template for displaying all pages
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site may use a
 * different template.
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package sample
 */

get_header(); ?>

<div id="primary" class="content-area">
    <main id="main" class="site-main">

        <?php
        while ( have_posts() ) : the_post(); ?>


            <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

                <?php // YOUR CONTENT AND TEMPLATE for PAGES GOES HERE ?>

            </article><!-- #post-<?php the_ID(); ?> -->



            <?php 
            // get_template_part( 'template-parts/content', 'page' );
            // as you can see i just copied the content of content-page.php here
            // and commented out the get_template_part function
            // you can delete this, it is just to explain a little more ;)
            ?>

            <?php

            // If comments are open or we have at least one comment, load up the comment template.
            if ( comments_open() || get_comments_number() ) :
                comments_template();
            endif;

        endwhile; // End of the loop.
        ?>

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

<?php
get_sidebar();
get_footer();
| improve this answer | |
  • Thanks for your help. I don't know what I did wrong the first time, but now it is working... I think I just forgot a ?> the first time somewhere... – marou Nov 20 '17 at 16:47
  • Classic eheh! Happy if i was able to help you solve this. Tag this answer as problem solving ;) have a good one :) – Julien G Nov 21 '17 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.