在Wordpress中突出显示当前页面/内容类型

时间:2012-10-02 16:11:41

标签: 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();
?>

1 个答案:

答案 0 :(得分: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();
    ?>