Skip to content

Instantly share code, notes, and snippets.

@kachi
Created June 24, 2015 00:39
Show Gist options
  • Save kachi/d90185797c7f89fc2009 to your computer and use it in GitHub Desktop.
Save kachi/d90185797c7f89fc2009 to your computer and use it in GitHub Desktop.
<?php //ループ内に書く
$previous_post = get_previous_post();
$next_post = get_next_post();
$prev_value = get_post_meta( $previous_post->ID, 'CUSTOM_FIELD', $single = true); //CUSTOM_FIELDが表示したいカスタムフィールドの名前
$next_value = get_post_meta( $next_post->ID, 'CUSTOM_FIELD', $single = true);
?>
<?php if ( $prev_value != '' ) : ?>
<p><?php echo $prev_value; ?></p><!--ここに前の記事に与えたCUSTOM_FIELDという名前のカスタムフィールドの値が表示される-->
<p><?php echo $next_value; ?></p><!--ここは次の記事-->
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment