Skip to content

Instantly share code, notes, and snippets.

@ShinichiNishikawa
Last active October 2, 2015 03:28
Show Gist options
  • Save ShinichiNishikawa/2162840 to your computer and use it in GitHub Desktop.
Save ShinichiNishikawa/2162840 to your computer and use it in GitHub Desktop.
カスタム投稿タイプの投稿一覧で現在表示にcurrentを持たせる
<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