Last active
December 11, 2015 09:29
-
-
Save ShinichiNishikawa/4580504 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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