1. TOP
  2. wordpress
  3. 固定ページ作成

固定ページ作成

ここでは投稿ページとは違う固定ページを作っておきます。

まずは以下のサンプルをpage.phpとして保存しておきます

サンプル

<?php get_header(); ?>

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

<?php the_post(); ?>

<div class=”page-title”>
<h1><?php the_title(); ?></h1>
</div>

<div class=”content-area content-area-profile”>
<div class=”main-column”>
<div class=”box-content radius-tl”>
<article>
<?php the_content(); ?>
</article>
</div>
</div>

<?php if ( comments_open() || get_comments_number() ) :
comments_template();
endif; ?>

</div>

<?php endwhile; ?>

<?php get_footer();

フッター、ヘッダーのインクルードとループ

毎度おなじみですがここでも<?php get_header(); ?><?php get_footer();を最初と最後に入れてヘッダー、フッターを読み込んでおきます。

<?php if ( comments_open() || get_comments_number() ) :
comments_template();
endif; ?>

上記の固定ページのコメントはほとんど有効化されませんが、個別にコメントを有効化することができます。

さてここではページの内容を表示するために、こちらもおなじみのループを利用していきます。

<?php get_header(); ?>

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

<?php the_post(); ?>

============(略)=================

<?php endwhile; ?>

 

while文ですね。

ここではプロフィールページを作ります。

<h1><?php the_title(); ?></h1>

ここでタイトルを入れて

<article></article>内の<?php the_content(); ?>に本文が入ります。

Leave a comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です