Skip to content

Instantly share code, notes, and snippets.

@Olein-jp
Created June 25, 2021 23:22
Show Gist options
  • Save Olein-jp/8b8dd937939a25420bf85427c94e8a05 to your computer and use it in GitHub Desktop.
Save Olein-jp/8b8dd937939a25420bf85427c94e8a05 to your computer and use it in GitHub Desktop.
Output Advanced Custom Fields on Snow Monkey
/**
* カスタム投稿タイプのアーカイブページにAFC情報を掲載する
*/
add_filter(
'snow_monkey_template_part_render_template-parts/loop/entry-summary/content/content',
function( $html ) {
if ( is_post_type_archive( 'custom_post_type' ) ) {
$match_date = get_field( 'match_date' );
$match_score = get_field( 'match_score' );
$match_result = get_field( 'match_result' );
$match_result_sign = $match_result === 'win' ? '●' : '×';
return str_replace(
'</div>',
'</div>' . '<ul><li>日時:' . $match_date . '</li><li>スコア:' . $match_score . '</li><li>勝敗:' . $match_result_sign . '</li></ul>',
$html
);
}
}
);
/**
* カスタム投稿タイプの投稿詳細ページにAFC情報を掲載する
*/
add_action(
'snow_monkey_prepend_entry_content',
function() {
if ( get_post_type() === 'custom_post_type' ) {
$match_date = get_field( 'match_date' );
$match_score = get_field( 'match_score' );
$match_result = get_field( 'match_result' );
$match_result_sign = $match_result === 'win' ? '●' : '×';
?>
<table>
<tr>
<th>日時</th>
<td><?php echo $match_date; ?></td>
</tr>
<tr>
<th>スコア</th>
<td><?php echo $match_score; ?></td>
</tr>
<tr>
<th>勝敗</th>
<td><?php echo $match_result_sign; ?></td>
</tr>
</table>
<?php
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment