0

カスタム投稿タイプ「サービス」からメニューを作成しています。現在のページを強調表示したいと思います。それ、どうやったら出来るの?

以下のコード (このコードの下) では、助けが必要なこの部分を除いて、すべてが機能します。

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();
?>
4

1 に答える 1

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();
    ?>
于 2012-10-02T16:16:48.563 に答える