●質問
URL: http://iphone-nippon.com/
Ver: STINGER3 20131023
メッセージ本文:
関連記事をタグ重視にする方法が知りたいです。
さらに、タグランダム表示とかできるとより嬉しいです。
-------------------------------------------
※先に要バックアップ
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
<!--関連記事--> <h4 class="kanren">関連記事</h4> <div class="sumbox02"> <?php $cur_post = $wp_query->get_queried_object(); $post_cats = get_the_category($cur_post->ID); ?> <div id="topnews"> <div><?php $original_post = $post; $tags = wp_get_post_tags($post->ID); $tagIDs = array(); if ($tags) { $tagcount = count($tags); for ($i = 0; $i < $tagcount; $i++) { $tagIDs[$i] = $tags[$i]->term_id; } $args=array( 'tag__in' => $tagIDs, 'post__not_in' => array($post->ID), 'showposts'=>5, 'orderby' => 'rand', 'caller_get_posts'=>1 ); $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?> <dl><dt> <?php if ($post->ID == $cur_post->ID) : ?> <?php else :?> <a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"> <?php if ( has_post_thumbnail() ): // サムネイルを持っているときの処理 ?> <?php echo get_the_post_thumbnail($post->ID, 'thumb110'); ?> <?php else: // サムネイルを持っていないときの処理 ?> <img src="<?php echo get_template_directory_uri(); ?>/images/no-img.png" alt="no image" title="no image" width="110px" /> <?php endif; ?> </a> <?php endif; ?> </dt> <dd> <?php if ($post->ID == $cur_post->ID) : ?> <?php else :?> <h4 class="saisin"> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4> <p class="basui"> <?php echo mb_substr(strip_tags($post-> post_content),0,35).'...'; ?></p> <p class="motto"><a href="<?php the_permalink(); ?>">記事を読む</a></p> <?php endif; ?> </dd></dl> <?php endwhile; wp_reset_query(); ?> <?php } else { ?> 関連する記事は見当たりません… <?php } } ?> </div> </div> </div> <!--/関連記事--> |
ランダムじゃない時は
1 |
'orderby' => 'rand', |
を削除