前提・実現したいこと
ワードプレスでテーマを作成しています。
その時に各記事にカテゴリーを付けれるようにしたのですが、このように一つの枠内にカテゴリーが入ってしまいます。
それを二つに分けれるようにしたいです。
カテゴリー内でまたループ?みたいのを使うのでしょうか??
お手数おかけしますが回答お待ちしております。( ; ; )
足りない情報などありましたら教えていただければありがたいです。。。
該当のソースコード
php
1<ul class="col col2 col_sp_full"> 2 3 <?php 4 $args = array( 5 'post_type' => 'ceo', 6 'posts_per_page' => 12 7 ); 8 $query = new WP_Query( $args ); 9 ?> 10 11 <?php if ( $query->have_posts() ) : ?> 12 <?php while ( $query->have_posts() ) : $query->the_post();?> 13 14 <li class="article"> 15 <a href="<?php the_permalink(); ?>"> 16 <?php if( get_the_post_thumbnail() ) { ?> 17 <div class="post-thumbnail"> 18 <?php the_post_thumbnail(array(360,240)); ?> 19 </div> 20 <?php }else{ ?> 21 <img src="<?php echo get_template_directory_uri(); ?>/images/no-image.jpg"> 22 <?php } ?> 23 <div class="child"> 24 <span class="tag"> 25 <?php 26 if ($terms = get_the_terms($post->ID, 'ceo_category')) { 27 foreach ( $terms as $term ) { 28 echo esc_html($term->name); 29 } 30 } 31 ?> 32 </span> 33 <span class="date"><?php the_time( 'Y.m.d' ); ?></span></div> 34 <h4><?php 35 if(mb_strlen($post->post_title, 'UTF-8')>30){ 36 $title= mb_substr($post->post_title, 0, 30, 'UTF-8'); 37 echo $title.'…'; 38 }else{ 39 echo $post->post_title; 40 } 41 ?> 42 </h4> 43 </a> 44 </li> 45 <?php endwhile; ?> 46 <?php endif; wp_reset_postdata(); ?> 47 </ul>
php
1add_action( 'init', 'create_post_type_ceo' ); 2function create_post_type_ceo() { 3register_post_type( 'ceo', //カスタム投稿タイプ名 4array( 5'labels' => array( 6'name' => __( '社長のブログ' ), 7'all_items' => __( '社長のブログ一覧' ), 8 9), 10'public' => true, 11'has_archive' => true, //アーカイブページを持つ 12'menu_position' =>5, //管理画面のメニュー順位 13'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'custom-fields' ,'comments' ), 14) 15); 16/* カテゴリーの設定 */ 17register_taxonomy( 18'ceo_category', //カテゴリーの名前 19'ceo', //使うカスタム投稿タイプ名 20array( 21'hierarchical' => true, //trueで親子関係使用 22'update_count_callback' => '_update_post_term_count', 23'label' => 'カテゴリー', 24'singular_label' => 'カテゴリー', 25'public' => true, 26'show_ui' => true 27) 28); 29/* タグを設定 */ 30register_taxonomy( 31'ceo_tag', //タグの名前 32'ceo', //使うカスタム投稿タイプ名 33array( 34'hierarchical' => false, 35'update_count_callback' => '_update_post_term_count', 36'label' => 'タグ', 37'singular_label' => 'タグ', 38'public' => true, 39'show_ui' => true 40) 41); 42} 43
css
1ul.col { 2 display: flex; 3 flex-flow: row wrap; } 4 ul.col > li { 5 flex: 0 0 50%; 6 width: 50%; 7 /* before Android4.3 iOS6:Safari */ 8 max-width: 50%; 9 /* IE11*/ 10 height: auto; } 11 12ul.col2 > li { 13 flex: 0 0 48%; 14 width: 48%; 15 /* before Android4.3 iOS6:Safari */ 16 max-width: 48%; 17 /* IE11*/ 18 height: auto; 19 margin-right: 4%; 20 margin-bottom: 5%; } 21 ul.col2 > li:nth-child(2n) { 22 margin-right: 0; } 23 24 25.child { 26 margin: 20px 0; } 27 .child .tag { 28 border: 1px solid #0088c4; 29 color: #0088c4; 30 font-size: 1rem; 31 padding: 2px 8px; 32 text-align: center; 33 border-radius: 30px; } 34 @media screen and (max-width: 767px) { 35 .child .tag { 36 font-size: 1rem; 37 width: 9rem; } } 38 .child .date { 39 color: #999; 40 font-size: 1rem; } 41 42.tag { 43 display: inline-block; 44 align-items: center; 45 margin: 0 10px 0 0; } 46 .tag span { 47 border: 1px solid #0088c4; 48 color: #0088c4; 49 font-size: 1.2rem; 50 padding: 4px 8px; 51 text-align: center; 52 border-radius: 30px; } 53 @media screen and (max-width: 767px) { 54 .tag span { 55 font-size: 1rem; 56 width: 9rem; } } 57 58
回答1件
あなたの回答
tips
プレビュー