wordpress の作業データ(4月25日分)
トップページ
front-page.php
<?php /* Template Name:blogサイトのトップページ */ ?> <!DOCTYPE html> <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><!-- /.wp-post-wrapper --> </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,//1枚の画像の幅 shrinkItems: true, }); }); </script> </body> </html>
ブログページ
index.php
<?php /* Template Name:blogサイトのブログページ */ ?> <!DOCTYPE html> <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><!-- /.post-box --> </a> <!-- ここまで投稿 --> <?php endwhile; //投稿ループ終了 ?> <!-- ページネーション開始 --> <?php the_posts_pagination(); ?> <!-- ページネーション終了 --> <?php else: ?> <?php endif; //条件分岐終了 ?> </div> </body> </html>
style.css
@charset "utf-8"; /* Theme Name:felica-blog Author:yajima */ html{box-sizing:border-box;-webkit-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;-webkit-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]{-webkit-appearance:textfield}[type=search]::-webkit-search-cancel-button,[type=search]::-webkit-search-decoration{-webkit-appearance:none}textarea{overflow:auto;resize:vertical}button,input,optgroup,select,textarea{font:inherit}optgroup{font-weight:700}button{overflow:visible}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button::-moz-focus-inner{border-style:0;padding:0}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button:-moz-focusring{outline:1px dotted ButtonText}[type=reset],[type=submit],button,html [type=button]{-webkit-appearance:button}button,select{text-transform:none}button,input,select,textarea{background-color:transparent;border-style:none;color:inherit}select{-moz-appearance:none;-webkit-appearance:none}select::-ms-expand{display:none}select::-ms-value{color:currentColor}legend{border:0;color:inherit;display:table;max-width:100%;white-space:normal}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}[type=search]{-webkit-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}::-moz-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; }