hanuman6
11/24/2013 - 9:07 AM

指定のタクソミーからタームを自動取得し一覧表示

指定のタクソミーからタームを自動取得し一覧表示

<?php
$args = array(
    'hideempty' => 1
);
$term_objs = get_terms('class',$args);
foreach ($term_objs as $term_obj) :
?>
    <h3 class="terms"><?php echo esc_html($term_obj->name); ?></h3>
<?php
    $args = array (
        'post_type'   => 'columns',
        'class'     => $term_obj->slug,
        'numberposts' => -1,
    );
    $myposts = get_posts($args);
    echo '<ul style="margin-top:0">';
    foreach ($myposts as $post) :
        setup_postdata($post);
?>


					<li>
					<p class="date"><?php the_time('Y年m月d日'); ?></p>
					<a href="<?php the_permalink(); ?>">
					<h3>
					  <?php 
					    if (strlen($post->post_title) > 30) {
					    echo mb_substr(the_title($before = '', $after = '', FALSE), 0, 30) . '...'; 
					    } else {
					    the_title();
					    }; ?>
					</h3>
					</a>
					</p>
					</li>


<!--         <li>
    	    <a href="<?php the_permalink(); ?>"><?php the_title();?></a> <?php the_terms($post->ID, 'class', '投稿者: ', '', ''); ?>
        </li> -->
<?php
    endforeach;
    echo '</ul>';
endforeach;
wp_reset_postdata();
?>
</article>