Create a gist now

Instantly share code, notes, and snippets.

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'] );
if ( isset($post_id) ):
$data = get_posts( array (
'post_type' => 'property',
'post_per_page' => 1,
'p' => $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