Skip to content

Instantly share code, notes, and snippets.

@mypacecreator
Last active August 25, 2022 03:07
Show Gist options
  • Save mypacecreator/5a1700f1dff7fc7476e9006944671ce5 to your computer and use it in GitHub Desktop.
Save mypacecreator/5a1700f1dff7fc7476e9006944671ce5 to your computer and use it in GitHub Desktop.
WordPressで印刷用画面を作る(ブログ用)
<!DOCTYPE HTML>
<html lang="ja">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<meta name="robots" content="noindex">
<title>印刷用ページのベース(例)</title>
<link rel='stylesheet' id='print-css' href='<?php echo esc_url( get_template_directory_uri() ); ?>/print.css' type='text/css' media='all' />
</head>
<body>
<?php
parse_str( $_SERVER['QUERY_STRING'], $array );
if ( isset( $array['post_id'] ) ) :
$data = get_posts( array (
'post_type' => 'property',
'post_per_page' => 1,
'p' => $array['post_id'],
));
foreach($data as $post):
setup_postdata($post);
?>
<!-- ここは通常のWordPressループと同じようにテンプレートタグなどを入れる -->
<p class="print-btn"><a href="javascript:void(0)" onclick="window.print();return false;">このページを印刷</a></p>
<?php
endforeach;
wp_reset_postdata();
?>
<?php else: ?>
<p>このページにはなにもないよ!</p>
<?php endif; ?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment