从WP循环中排除当前页面


Exclude current page from WP loop

我使用简单的HTML和Php构建了一个导航。这很简单,但我希望它是:

  1. 从循环中排除当前帖子,因此它不出现或
  2. 有某种类型的识别样式更改,以显示它是当前页面。

外面有几页,但我试过了都没用。有人有什么想法吗?

代码:

<div class="project-nav" style="display:none;">
	<div class="nav-container">	
		<?php
		$catPost = get_posts('cat=5&posts_per_page=-1000');
		foreach ($catPost as $post) : setup_postdata($post); ?>
			<a href="<?php the_permalink(); ?>">
				<div class="nav-fixed">
					<p><?php the_title(); ?></p>
				</div>
			</a>
		<?php  endforeach;?>
	</div>
</div>

试试这个:

<div class="project-nav" style="display:none;">
    <div class="nav-container"> 
    <?php
    $current_id =  get_the_ID();
    $catPost = get_posts('cat=5&posts_per_page=-1000');
    foreach ($catPost as $post) : setup_postdata($post);
        if ( get_the_ID() == $current_id ) {
            continue;
        }
    ?>
    <a href="<?php the_permalink(); ?>">
            <div class="nav-fixed">
                <p><?php the_title(); ?></p>
            </div>
    </a>
    <?php  endforeach;?>
</div>