帖子类型:当前帖子 在帖子列表中已签入


Post Type: Current Post Checked in the list of posts

我在WP中有一个帖子类型,还有一个菜单,其中包含这样的帖子列表:

<ul class="menu2">  
        <?php
        $query = new WP_Query( array( 'post_type' => array( 'comisarios' ) ) );  
                while ( $query->have_posts() ) : $query->the_post();
                    echo '<li ';
                    echo '><a href="';
                    the_permalink();
                    echo '">';
                    the_title();
                    echo '</a></li>';
                endwhile;?>
    </ul>

我想知道如何选择当前帖子以添加诸如"class="selected"之类的文本,以显示黑色或其他内容。

谢谢!

<ul class="menu2">  
        <?php
        $postId = get_the_ID();
        $query = new WP_Query( array( 'post_type' => array( 'comisarios' ) ) );  
                while ( $query->have_posts() ) : $query->the_post();
                   $idPost = get_the_ID();                
                    echo '<li ';
                    if( $idPost==$postId)  echo 'class="selected"';
                    echo '><a href="';
                    the_permalink();
                    echo '">';
                    the_title();
                    echo '</a></li>';
                endwhile;?>
    </ul>

它是单帖子.php模板中的侧边栏菜单(在这种情况下,存档帖子模板无关紧要)。

这里是完整的代码:

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div class="main">
    <div class="boxCenter">
        <div class="content"><!-- CONTENT -->
            <div class="mainContent">
                <div class="entry">
                    <div class="textBoxSmall">
                        <div class="comisario">
                            <img src="<?php the_field('imagen_del_comisario'); ?>">
                        </div>
                        <div class="textSmall comisarioText">
                            <h1><?php echo get_the_title(); ?></h1>
                            <p><?php the_field('res_comisario'); ?></p>      
                            <a href="http://<?php the_field('web_del_comisario'); ?>"><?php the_field('web_del_comisario'); ?></a> 
                            </p>
                            <p>Exposiciones:</p>
                            <div class="exposiciones">
                                <?php while(have_rows('exposiciones_del_comisario')): the_row(); ?>
                                    <?php 
                                        $contador++;
                                    ?>
                            <div class="square box<?php echo $contador; ?>">
                                <div class="center">
                                    <a href="<?php the_sub_field('exposicion'); ?>">
                                        <?php echo $contador; ?>
                                    </a>
                                </div>
                            </div>
                            <?php endwhile; ?>  
                        </div>  
                    </div>
                </div>

                <div class="textBox">
                  <?php the_content();?>
            </div>    
        </div>
    </div>      
</div><!-- CONTENT END -->
<?php endwhile; // end of the loop. ?>   

<div class="sidebar hide"><!-- LATERAL MENU -->
    <ul class="menu2">  
        <?php
        $query = new WP_Query( array( 'post_type' => array( 'comisarios' ) ) );  
                while ( $query->have_posts() ) : $query->the_post();
                    echo '<li ';
                    echo '><a href="';
                    the_permalink();
                    echo '">';
                    the_title();
                    echo '</a></li>';
                endwhile;?>
    </ul>
</div><!-- END LATERAL MENU -->