目前,下面所有代码都显示了来自当前页面所在类别的3篇随机帖子。因此,如果当前页面属于“艺术家”类别,例如,请在页面的下面显示“艺术家”类别中的3篇随机帖子。我的问题是,当前帖子一直出现在这一部分中,我想将其排除在外,但无法使用我当前的循环来解决此问题。这是我的循环:
<?php if ( in_category( \'artists\' ) ) { ?>
<h2>Similar articles</h2>
<?php // Display the 3 random posts from page category
query_posts(\'showposts=3&cat=1,-12&orderby=rand\'); ?>
<?php } ?>
<?php if ( in_category( \'people\' ) ) { ?>
<h2>Similar articles</h2>
<?php // Display the 3 random posts from page category
query_posts(\'showposts=3&cat=3&orderby=rand\'); ?>
<?php } ?>
<?php if ( in_category( \'development\' ) ) { ?>
<h2>Similar articles</h2>
<?php // Display the 3 random posts from page category
query_posts(\'showposts=3&cat=5&orderby=rand\'); ?>
<?php } ?>
<?php if ( in_category( \'offsite\' ) ) { ?>
<h2>Similar articles</h2>
<?php // Display the 3 random posts from page category
query_posts(\'showposts=3&cat=7&orderby=rand\'); ?>
<?php } ?>
<?php if ( in_category( \'projects\' ) ) { ?>
<h2>Similar articles</h2>
<?php // Display the 3 random posts from page category
query_posts(\'showposts=3&cat=6&orderby=rand\'); ?>
<?php } ?>
<?php if ( in_category( \'contact\' ) ) : // Display nothing ?>
<?php // Else, show boxes
else : ?>
<?php while (have_posts()) : the_post(); ?>
<?php foreach( get_the_category() as $cat ) echo \'<div class="module \' . $cat->slug . \'" data-category="\' . $cat->slug . \'" >\'; ?>
<a href="<?php the_permalink()?>" title="<?php the_title(); ?>">
<div class="active">
<div class="hover"> </div>
<?php the_post_thumbnail(); ?>
</div>
<?php
$sub_title=get_post_meta($post->ID,\'subtitle\',true);
if($sub_title != \'\') {
echo \'<h1>\'. get_the_title() .\'<span> / \'. $sub_title .\'</span></h1>\';
} else {
echo \'<h1>\'. get_the_title() .\'</h1>\';
}
?>
<?php
// Call in the contents of a custom field called Excerpt and if custom field in admin panel is empty don\'t display <p> tags otherwise wrap contents in <p> tags
$excerpt=get_post_meta($post->ID,\'Excerpt\',true);
if($excerpt != \'\') {
echo \'<p>\'. $excerpt .\'</p>\';
} else {
echo \' \';
}
?>
<p class="date"><?php the_time(\'YdmHi\') ?></p>
</a>
</div>
<?php endwhile;?>
<?php endif; ?>