0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

wordpress singlepage 画像、タイトル、本文取得

Last updated at Posted at 2019-11-06

アイキャッチ画像

single.php
アイキャッチ画像のURLを出力
the_post_thumbnail_url( 'medium' );

アイキャッチ画像のURLを取得
get_the_post_thumbnail_url( get_the_ID(), 'medium' );
 取得して出力する場合(echoをつけることで出力が可能)
 echo get_the_post_thumbnail_url();

記事の投稿タイトル

single.php
記事のタイトルを出力
<?php the_title(); ?>

wordpressループ内で使用する タイトルのみを一覧表示例
<?php if ( have_posts() ) : ?>
  <?php while ( have_posts() ) : the_post(); ?>
      <h2><?php the_title(); ?></h2>
  <?php endwhile;?>
<?php endif; ?>

タイトルのURLを取得
・タグなどを含めて取得したい場合
 <?php $title = the_title( '', '', false ); ?>
・引数を指定しない場合、現在の投稿タイトルを返す
 <?php $title = get_the_title(); ?>

記事の本文

single.php
本文を出力する
<?php the_content(); ?>

記事のタイトルと本文を出力するループで 一覧表示例
<?php if ( have_posts() ) : ?>
  <?php while( have_posts() ) : the_post(); ?>
      <h2><?php the_title(); ?></h2>
      <p><?php the_content(); ?></p>
  <?php endwhile;?>
<?php endif; ?>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?