previous_image_link

Sponsored Link

現在のポストに添付された前の画像へのリンクを作成します。

Sponsored Link

This creates a link to the previous image attached to the current post.

previous_image_linkのテンプレートタグ使用方法

<?php previous_image_link( $size, $text ); ?>

previous_image_linkのパラメーター

$size

(string) (optional) 画像のサイズ、配列または文字列。 0またはnoneは、post_titleまたは$textがデフォルトです。

(string) (optional) Size of image, either array or string. 0 or none will default to post_title or $text.

Default: thumbnail

$text

(string) (optional) もしインクルードされた場合は、リンクは$text変数が反映されます。

(string) (optional) If included, link will reflect $text variable.

Default: false

デフォルトの使い方

<?php previous_image_link(); ?>

作業の例

<div class="alignleft"><?php previous_image_link() ?></div>

認識している画像サイズを選択

<?php previous_image_link( 'thumbnail' ); ?>
<?php previous_image_link( 'medium' ); ?>
<?php previous_image_link( 'large' ); ?>
<?php previous_image_link( 'fullsize' ); ?>

カスタム画像サイズを定義する

<?php previous_image_link( array( 37, 37 ) ); ?>

最初のパラメーター配列として渡すということは、新しい画像を作成しないので、注意してください。これは、リサイズにサムネイルが指定された寸法に収まるようにWebブラウザを使用します。たとえこの方法がピンチでも、ブラウザーがリサイズされた画像を見本にする方法がない事が事実なので、画像がかなりゆがんだ表示で生成します。

Please note that passing an array as the first parameter will not create a new image; It will use the web browser to re-size the thumbnail to fit into the given dimensions. Although this works in a pinch, it produces a rather distorted view of the image due to the fact that browsers have no way of re sampling the re-sized image.

画像のタイトルをテキストリンクとして使用する方法

Booleanのfalseが最初のパラメーターとして使用されている場合、この関数は画像のタイトル値(メディアライブラリを介して設定)使用します。

If a Boolean false is used as the first parameter, The function will use the image’s title value (as set through the Media Library).

<?php previous_image_link( false ); ?>
<?php previous_image_link( 0 ); ?>

リンクテキストとしてカスタム文字列を使用する方法

リンクテキストとしてカスタム文字列を指定すると、Booleanは最初のパラメーターとしてfalseを、2番目のパラメーターに文字列としてカスタムテキストを渡します。ブールfalseとして渡します。

To specify a custom string as the link text, pass a Boolean false as the first parameter and the custom text as a string to the second parameter.

<?php previous_image_link( false, 'Previous Image' ); ?>

変更ログ

  • Since: 2.5.0
  • 2.8 added 2 parameters: $size and $text

関連テンプレートタグ

See also next_image_link()

Sponsored Link