Menu

Adding “current” class if using get_pages

February 12, 2014 - wordpress
<?php
$current_id = get_the_ID();
$mypages = get_pages('child_of='.$post->post_parent.'&sort_column=menu_order&hierarchical=0');

	if($mypages)
	{
		foreach($mypages as $page)
		{
		$link_page_id = ($page->ID)
	?>

<li>
	<a <?php if ($current_id == $link_page_id) : ?> <?php else : ?><?php endif; ?>class="current" <?php else : ?><?php endif; ?> href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a>

</li>
	<?php
		}
	}
?>









Another Code


<?php get_header(); ?>

	<div id="content">
		<div id="content-pri">
<?php if (have_posts()) : while (have_posts()) : the_post(); $current_project = get_the_ID(); ?>
			<h2><?php the_title(); ?></h2>
			<?php the_content(); ?>
<?php endwhile; endif; ?>
		</div> <!-- // #content-pri -->
		<aside>
			<h3>Recent projects</h3>
			<ul>
<?php $loop = new WP_Query(array('post_type' => 'portfolio')); while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php if ( $post->ID == $current_project ) { ?>
				<li><?php the_title(); ?></li>
<?php } else { ?>
				<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php } ?>
<?php endwhile; ?>
			</ul>
		</aside>
	</div> <!-- // #content -->

<?php get_footer(); ?>
 

Leave a Reply