Last active
October 2, 2015 03:28
-
-
Save ShinichiNishikawa/2162840 to your computer and use it in GitHub Desktop.
カスタム投稿タイプの投稿一覧で現在表示にcurrentを持たせる
This file contains hidden or 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
<ul> | |
<?php | |
$current_page_id = $wp_query->get_queried_object_id(); | |
$args = array( | |
'post_type' => 'yourcustomposttype', | |
); | |
$your_posts = get_posts($args); | |
foreach ( $your_posts as $post ) { | |
setup_postdata($post); | |
$current_class = null; | |
$listed_page_id = null; | |
$listed_page_id = $post->ID; | |
if ( $listed_page_id == $current_page_id ) { | |
$current_class = ' current_page_item'; | |
} | |
?> | |
<li class="page_item<?php echo $current_class; ?>"><a href="<?php the_permalink() ?>"><?php the_title() ?></a></li> | |
<?php | |
} | |
?> | |
</ul> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment