トップページ
front-page.php
<?php
/* Template Name:blogサイトのトップページ */
?>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>wp-blogのトップページ</title>
<link rel="stylesheet" href="<?php echo get_stylesheet_uri(); ?>">
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/jquery.bxslider.css">
</head>
<body <?php body_class(); ?>>
<header>
<h1>wp-blogのトップページ</h1>
<p>サイトのキャッチフレーズ</p>
</header>
<main>
<div class="main-visual">
<ul class="bxslider">
<li><img src="<?php echo get_template_directory_uri(); ?>/img/01.jpg" alt=""></li>
<li><img src="<?php echo get_template_directory_uri(); ?>/img/02.jpg" alt=""></li>
<li><img src="<?php echo get_template_directory_uri(); ?>/img/03.jpg" alt=""></li>
<li><img src="<?php echo get_template_directory_uri(); ?>/img/04.jpg" alt=""></li>
</ul>
</div>
<div class="wp-post-wrapper">
<h2>Blog</h2>
<dl class="post-list">
<?php
$arg = array(
'posts_per_page' => 3, // 表示する件数
'orderby' => 'date', // 日付でソート
'order' => 'DESC', // DESCで最新から表示、ASCで最古から表示
//'category_name' => 'osaka', // 表示したいカテゴリーのスラッグを指定
'tag' => 'travel'//表示したいタグをスラッグ指定
);
$posts = get_posts( $arg );
if( $posts ): ?>
<?php
foreach ( $posts as $post ) :
setup_postdata( $post );
?>
<dt><?php the_time('Y年m月d日'); ?></dt>
<dd>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</dd>
<?php endforeach; ?>
<?php
/// 必ずクエリをリセット
endif;
wp_reset_postdata();
?>
</dl>
<a href="<?php echo esc_url( home_url() ); ?>/blog/">blogページへ</a>
</div>
</main>
<footer>
<p>サイトのタイトルが入る</p>
</footer>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js'></script>
<script src="<?php echo get_template_directory_uri(); ?>/js/jquery.bxslider.js"></script>
<script>
$(function(){
$('.bxslider').bxSlider({
maxSlides: 4,
ticker: true,
speed: 40000,
slideWidth: 600,
shrinkItems: true,
});
});
</script>
</body>
</html>
ブログページ
index.php
<?php
/* Template Name:blogサイトのブログページ */
?>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ブログページ</title>
<link rel="stylesheet" href="<?php echo get_stylesheet_uri(); ?>">
</head>
<body <?php body_class(); ?>>
<div class="post-wrapper">
<?php if(have_posts()): ?>
<?php while (have_posts()): ?>
<?php the_post(); ?>
<a href="<?php the_permalink(); ?>">
<div class="post-box">
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<p class="date"><?php the_time('Y年n月j日'); ?></p>
</div>
</a>
<?php endwhile; //投稿ループ終了 ?>
<?php the_posts_pagination(); ?>
<?php else: ?>
<?php endif; //条件分岐終了 ?>
</div>
</body>
</html>
style.css
@charset "utf-8";
html{box-sizing:border-box;text-size-adjust:100%}*,:after,:before{background-repeat:no-repeat;box-sizing:inherit}:after,:before{text-decoration:inherit;vertical-align:inherit}*{padding:0;margin:0;box-sizing:border-box;}audio:not([controls]){display:none;height:0}hr{overflow:visible}article,aside,details,figcaption,figure,footer,header,main,menu,nav,section,summary{display:block}summary{display:list-item}small{font-size:80%}[hidden],template{display:none}abbr[title]{border-bottom:1px dotted;text-decoration:none}a{background-color:transparent;text-decoration-skip:objects}a:active,a:hover{outline-width:0}code,kbd,pre,samp{font-family:monospace,monospace}b,strong{font-weight:bolder}dfn{font-style:italic}mark{background-color:#ff0;color:#000}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}input{border-radius:0}[role=button],[type=button],[type=reset],[type=submit],button{cursor:pointer}[disabled]{cursor:default}[type=number]{width:auto}[type=search]{appearance:textfield}[type=search]::search-cancel-button,[type=search]::search-decoration{appearance:none}textarea{overflow:auto;resize:vertical}button,input,optgroup,select,textarea{font:inherit}optgroup{font-weight:700}button{overflow:visible}[type=button]::focus-inner,[type=reset]::focus-inner,[type=submit]::focus-inner,button::focus-inner{border-style:0;padding:0}[type=button]::focus-inner,[type=reset]::focus-inner,[type=submit]::focus-inner,button:focusring{outline:1px dotted ButtonText}[type=reset],[type=submit],button,html [type=button]{appearance:button}button,select{text-transform:none}button,input,select,textarea{background-color:transparent;border-style:none;color:inherit}select{appearance:none;appearance:none}select::expand{display:none}select::value{color:currentColor}legend{border:0;color:inherit;display:table;max-width:100%;white-space:normal}::file-upload-button{appearance:button;font:inherit}[type=search]{appearance:textfield;outline-offset:-2px}img{border-style:none;vertical-align: bottom}progress{vertical-align:baseline}svg:not(:root){overflow:hidden}audio,canvas,progress,video{display:inline-block}@media screen{[hidden~=screen]{display:inherit}[hidden~=screen]:not(:active):not(:focus):not(:target){position:absolute!important;clip:rect(0 0 0 0)!important}}[aria-busy=true]{cursor:progress}[aria-controls]{cursor:pointer}[aria-disabled]{cursor:default}::selection{background-color:#b3d4fc;color:#000;text-shadow:none}::selection{background-color:#b3d4fc;color:#000;text-shadow:none}ul,ol{list-style:none;}a{text-decoration:none;}.wrapper{overflow:hidden;}body{overflow-y:scroll;}img{max-width: 100%;}
header{
text-align: center;
padding: 30px 0;
}
header>h1{
margin-bottom: 20px;
}
.main-visual{
width: 100%;
margin-bottom: 100px;
}
.wp-post-wrapper{
max-width: 800px;
margin: 100px auto;
}
.wp-post-wrapper>h2{
text-align: center;
margin-bottom: 20px;
}
.post-list{
display: flex;
flex-wrap: wrap;
background-color: #e7effa;
}
.post-list>dt{
width: 30%;
padding: 20px;
}
.post-list>dd{
width: 70%;
}
.post-list>dd>a{
display: block;
padding: 20px;
color: #222;
}
.post-list>dd>a:hover{
text-decoration: underline 2px;
}
.post-list>dt:nth-of-type(even),.post-list>dd:nth-of-type(even){
background-color: #c5c5c5;
}
footer{
width: 100%;
height: 100px;
background-color: #5d5d5d;
color: #FFF;
}
.post-wrapper{
max-width: 960px;
margin: 100px auto;
}
a{
color: #222;
}
.post-box{
margin: 20px auto 40px;
background-color: #d9f1ef;
padding: 20px;
}
.post-wrapper h1{
margin-bottom: 20px;
}
.post-wrapper p{
margin-bottom: 20px;
}
.single-post .post-wrapper{
max-width: 1200px;
}
.single-post .post-box{
background-color: #eb7a91;
}
.single-post h1{
text-align: center;
}