Omegakenshin
Member
Posted 2 years ago #
I have a "navigation" with query_post and I want to add the class "current" when the child is the current page.
query_posts('post_type=page&post_parent=37&order=asc'); while (have_posts()) : the_post (); ?>
<li ADD CLASS HERE id="post-<?php the_ID(); ?>" > <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<img src="IMAGE HERE" alt="" />
</li>
<?php endwhile; wp_reset_query();
I didn't do it with register_nav_menus because I need to custom it a little with images.
Thanks
Try this:
$post_id = $post->ID;
query_posts('post_type=page&post_parent=37&order=asc'); while (have_posts()) : the_post (); ?>
<?php
$class = '';
if ($post_id == $post->ID){ $class = 'class="current" '; }
?>
<li id="post-<?php the_ID(); ?>" <?php echo $class ?>> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<img src="IMAGE HERE" alt="" />
</li>
<?php endwhile; wp_reset_query();
Omegakenshin
Member
Posted 2 years ago #
Excelent, that's it ^^, thanks a lot n.n
ryansebiz
Member
Posted 2 years ago #
Thanks kees - been banging my head against the wall for a couple hours trying to find this solution.
plantprojects
Member
Posted 2 years ago #
Where do you put this code, in the template file or functions.php?