Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShinichiNishikawa/4580504 to your computer and use it in GitHub Desktop.
Save ShinichiNishikawa/4580504 to your computer and use it in GitHub Desktop.
<?php
// タクソノミ取得
$catargs = array(
'taxonomy' => 'specialcat'
);
$catlists = get_categories( $catargs );
foreach($catlists as $cat) : // 取得したカテゴリの配列でループを回す
/*
// タクソノミひとつひとつのオブジェクトの中身を見る
if ( is_user_logged_in() ) {
echo '<pre>';
var_dump( $cat );
echo '</pre>';
}
*/
?>
<section>
<h3><a href="<?php echo home_url('/path/' . $cat->slug ); ?>"><?php echo $cat->name; ?></a></h3>
<p><?php echo $cat->category_description; ?></p><?php // 説明文 ?>
<ul>
<?php
$args = array(
'post_type' => 'special',
'specialcat' => $cat->slug
);
$my_posts = get_posts( $args );
if ( $my_posts ) { // 該当する投稿があったら
foreach ( $my_posts as $post ) :
setup_postdata( $post );
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php
endforeach;
} else {
echo 'このカテゴリに投稿はありません';
}
wp_reset_postdata();
?>
</ul>
</section>
<?php endforeach; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment