this is the code that I use to create a submenu that list all custom post I create in wordpress:
<ul class="submenu">
<img src="<?php bloginfo('template_directory'); ?>/images/submenu.png" alt="submenu" width="62" height="1" />
<!-- List post types -->
<?php
$the_query = new WP_Query( 'post_type=artworks_post' );
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
echo '<li id="submenu_link" class="submenu_item_link">';
echo '<a href="' .get_permalink(). '" > ';
the_title();
echo '</a>';
echo '</li>';
endwhile;
// Reset Post Data
wp_reset_postdata();
?>
<img src="<?php bloginfo('template_directory'); ?>/images/submenu.png" alt="submenu" width="62" height="1" />
</ul>
For example my current post is artworks_post/project-coke but it doesn´t add current/active class to the title of it in the submenu (Project Coke title).
How can I add an active/current class to the title of the current post in the submenu?
The submenu is constructed that way to get the custom post…
Try my code ? :
Put this code in your functions.php
So edit your code like :
Result :
PS: you can add whatever
if_current('text')in loop in your theme, This will show when$post->ID == $wp_query->get_queried_object_id()(if current)So you can use class current in your CSS