Create page.php for original theme

This is one of the articles about project “Create Original Theme in WordPress”.

GOAL

To create page.php

Environment

WordPress 5.5.1
XAMPP 7.4.10

page.php

page.php is used to display fixed page such as “About”, “Access”, “Contact” and so on.

<?php
/**
*this is the fixed page template
*@package WordPress
*@subpackage Techblog
*@since Techblog 1.0
*/
get_header(); ?>
<div class="container">
<main id="main" class="site-main">
	<?php
		while ( have_posts() ) : the_post(); ?>
			<?php get_template_part( 'content/content', 'page' ); ?>
			<?php
				// If comments are open or we have at least one comment, load up the comment template
				if ( comments_open() || '0' != get_comments_number() ) :
					comments_template();
				endif;
			?>
		<?php endwhile;?>
</main>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>

content/content-page.php

<?php
/**
 * The template used for displaying page content in page.php
*@package WordPress
*@subpackage Techblog
*@since Techblog 1.0
 */
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
	<div class= "main-content">
		<div class="page-item">
			<h1 class="entry-title"><?php the_title(); ?></h1>
			<div class="post-info">
				<span class="sns"><a href="https://twitter.com/share" data-url="<?php the_permalink(); ?>" data-text="<?php echo get_the_title(); ?>" class="twitter-share-button" data-via="nako_new_high" data-show-count="false">Tweet</a><script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></span><br/>
				<span class="post-date"><?php the_date();?></span>
			</div>
			<?php
				the_content();
				wp_link_pages();
			?>
			<?php if(get_edit_post_link()) : ?>
				<footer>
					<?php edit_post_link(); ?>
				</footer>
			<?php endif; ?>
		</div>
	</div>
</article>

page.php and content-page.php

content-page.php is one of the template parts that is loaded by using get_template_part() in page.php.

Functions

get_template_part($slug, $name )

This function loads a template part $slug.php or $slug-$name.php into a template.

comments_open()

Determines whether the current post is open for comments.

comments_templatestring $file = ‘/comments.php’)

This loads comment template defined by /comments.php, (but the comments.php is nor generated yet).

wp_link_pages()

The formatted output of a list of pages. This is used for repagination.

Result

Change the style