2012-10-02 54 views
0

从自定义帖子类型“服务”创建菜单,我想突出显示正在显示的页面。我怎么做?在Wordpress中突出显示当前页面/内容类型

一切都在代码工作如下(下面这段代码),除了这部分,我需要的帮助:

if (current_page_on == this_menu_item_from_loop) { 
    // This is the current page - highlight the <li> 
} 

...

<?php 
$type = 'services'; 
$args=array('post_type' => $type); 

$my_query = null; 
$my_query = new WP_Query($args); 
if($my_query->have_posts()) { 
    while ($my_query->have_posts()) : $my_query->the_post(); 
     if (current_page_on == this_menu_item_from_loop) { 
      // This is the current page - highlight the <li> 
     } 
    ?> 
     <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li> 
    <?php 
    endwhile; 
} 
wp_reset_query(); 
?> 

回答

0

我解决了它自己:)

<?php 
    $page_ID = get_the_ID(); 

    $type = 'services'; 
    $args=array(
     'post_type' => $type); 

    $my_query = null; 
    $my_query = new WP_Query($args); 
    if($my_query->have_posts()) { 
     while ($my_query->have_posts()) : $my_query->the_post(); 
      if (get_the_ID() == $page_ID) { 
       $current = ' class="current"'; 
      } 
     ?> 
      <li><a href="<?php the_permalink() ?>"<?php echo $current; ?>><?php the_title(); ?></a></li> 
     <?php 
      $current = ''; 
     endwhile; 
    } 
    wp_reset_query(); 
    ?> 
相关问题