wordpressのテーマを現在自作してます。
そこでカテゴリーごとの一覧を出そうと思っています。
表示はされるのですが中々うまくなりません。
<div class="sectionWrap">で囲んでいる記事ですが 現在は ■■←記事 最新の記事2つが表示されて終わってる状態です。 これを ■■ ■■ ■■ という感じで最新から記事がある分だけ<div class="sectionWrap">で囲んでるものを3つ表示させたいです。 よろしくお願いします。php
1<?php if(in_category('hibilog')):?> 2<div class="sectionWrap"> 3<?php 4 $args = array( 5 'post_type' => 'post', 6 'posts_per_page' => 2, 7 'category_name' => 'hibilog' 8 ); 9 $wp_query = new WP_Query($args); 10 if ( $wp_query->have_posts() ) { 11 while ( $wp_query->have_posts() ){ 12 the_post(); 13 $category = get_the_category(); 14 $cat_name = $category[0]->cat_name; 15?> 16<div class="column cf"> 17 <span class="<?php $cat=get_the_category(); $cat=$cat[0]; {echo $cat->slug;}?>"><a href="#"><?php echo $cat_name; ?></a></span> 18 <a href="<?php the_permalink(); ?>"> 19 <div class="img2"><img src="<?php the_post_thumbnail_url(); ?>"></div> 20 <h2 class="title"><?php the_title(); ?></h2> 21<p> 22<?php if(mb_strlen($post->post_content,'UTF-8')>50){ 23$content= str_replace('\n', '', mb_substr(strip_tags($post-> post_content), 0, 50,'UTF-8')); 24echo $content.'……'; 25}else{ 26echo str_replace('\n', '', strip_tags($post->post_content)); 27} 28?> 29</p> 30</a> 31</div> 32<?php 33 } 34 } 35 wp_reset_postdata(); 36?> 37</div>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/02/07 16:56
2019/02/07 17:24
2019/02/07 17:28
2019/02/07 18:56