2012-12-18 150 views
0

我試圖突出顯示菜單項,具體取決於它是否位於當前頁面上。下面的代碼當前突出顯示每個菜單項,因爲它位於foreach循環內。我如何突出顯示分類術語,如果它是在某個頁面上,並且只有該術語(而不是每個術語)?根據當前頁面突出顯示菜單項

    <?php $args = array('taxonomy' => 'blog'); 
         $terms = get_terms('blog', $args); 

         $count = count($terms); $i=0; 
         if ($count > 0) { 
          $cape_list = '<p class="my_term-archive">'; 
          echo $postid; 
          foreach ($terms as $term) { 
           $i++; 
           $absolute = get_bloginfo('url'); 
           $postid = get_the_ID(); 
           if($postid == "561") { 
            $term_list .= '<a class="menu-active" style="padding-left:30px;width:88%!IMPORTANT;" href="' . $absolute . '/blog/' . $term->slug . '" title="' . sprintf(__('View all post filed under %s', 'my_localization_domain'), $term->name) . '">' . $term->name . '</a>'; 
           } else { 
            $term_list .= '<a style="padding-left:30px;width:88%!IMPORTANT;" href="' . $absolute . '/blog/' . $term->slug . '" title="' . sprintf(__('View all post filed under %s', 'my_localization_domain'), $term->name) . '">' . $term->name . '</a>'; 
           } } ?> 

          <?php echo $term_list; } ?> 
+1

WordPress的有一個內置的導航功能。你爲什麼不使用它? http://codex.wordpress.org/Function_Reference/wp_nav_menu它添加一個類,如果它是選定的頁面。 – CharliePrynn

+0

@CharliePrynn我很樂意使用,但任何想法如何將我的代碼工作?它列出了自定義分類術語,因此它不是一個簡單的頁面列表。 – Rob

回答