我的问题需要一些帮助。
我正在建立一个分类页面,在上面的帖子需要显示自定义字段键“uitleg”的值“ja”在哪里。每个类别只有一个具有该值的帖子。我把这篇文章用作介绍文章。在这个帖子下面,我需要显示除介绍帖子以外的所有其他同类帖子。这部分很有魅力。
但后来发生了一些奇怪的事情。如果我在一个类别中得到4篇帖子(1篇介绍帖子和3篇其他帖子),下面的查询会在每个类别下重复4次。有没有办法阻止这一切?必须在我的一个foreach查询中。但我看不出哪里出了问题。任何人都能看到哪里出了问题?
提前感谢!
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php $drukproef = get_post_meta($post->ID, \'drukproef\', $single = true); ?>
<?php $drukproefimage = get_post_meta($post->ID, \'drukproefimage\', $single = true); ?>
<?php $actief = get_post_meta($post->ID, \'actief\', $single = true); ?>
<?php $uitleg = get_post_meta($post->ID, \'uitleg\', $single = true); ?>
<?php $artistnaam = get_post_meta($post->ID, \'artistnaam\', $single = true); ?>
<?php $artisturl = get_post_meta($post->ID, \'artisturl\', $single = true); ?>
<?php global $post;
$categories = get_the_category();
foreach ($categories as $category) :
?>
<?php
global $post;
$tmp_post = $post;
$myposts = get_posts(\'posts_per_page=1\' . \'&paged=\' . get_query_var(\'paged\') . \'&meta_key=uitleg&meta_value=ja&category=\'. $category->term_id);
foreach($myposts as $post) :
setup_postdata($post);
?>
<?php $thumb = get_post_meta($post->ID, \'thumb\', $single = true); ?>
<?php $drukproef = get_post_meta($post->ID, \'drukproef\', $single = true); ?>
<?php $drukproefimage = get_post_meta($post->ID, \'drukproefimage\', $single = true); ?>
<?php $actief = get_post_meta($post->ID, \'actief\', $single = true); ?>
<?php $uitleg = get_post_meta($post->ID, \'uitleg\', $single = true); ?>
<div class="titleactive">
<span id="drukproeftitel"><?php the_title(); ?>:</span>
<span id="drukproefactief"><?php echo $drukproef; ?></span>
<img src="<?php bloginfo(\'template_directory\'); ?>/images/uitleg-actief-ja.png" width="20" height="20" />
</div>
<div class="contentactive">
<div id="contentholder">
<div class="uitleg">
<?php the_content(\'\'); ?>
</div>
<div id="uitlegdivider"><img src="<?php bloginfo(\'template_directory\'); ?>/images/uitlegdivider.png" alt="" width="26" height="171" /></div>
<div class="voorbeeldimage">
<img src="<?php echo $drukproefimage; ?>" />
</div>
</div>
<div class="clearfix"></div>
</div>
<?php endforeach; ?>
<?php $post = $tmp_post; ?>
<div id="uitlegbanners">
<div class="inzendingen">Overige inzendingen</div>
</div>
<div class="clearfix"></div>
<?php
$posts = get_posts(\'posts_per_page=1000&category=\'. $category->term_id . \'&paged=\' . get_query_var(\'paged\'));
foreach($posts as $post) :
$thumb = get_post_meta($post->ID, \'thumb\', $single = true);
?>
<ul>
<?php if (!empty($thumb)) { ?>
<li>
<?php $thumb = get_post_meta($post->ID, \'thumb\', $single = true); ?>
<?php $artistnaam = get_post_meta($post->ID, \'artistnaam\', $single = true); ?>
<a href="<?php the_permalink(); ?>"><img src="<?php echo $thumb; ?>" class="img" alt="<?php the_title(); ?>" width="171" height="171" /></a>
<div class="corners"></div>
<a href="<?php the_permalink(); ?>">
<div class="info">
<h3><?php echo $artistnaam; ?></h3>
<div class="excerpt"><?php the_excerpt(); ?></div>
<div class="currentrating"><?php echo the_ratings_results(get_the_id()); ?></div>
</div>
</a>
</li>
<?php } ?>
</ul>
<?php endforeach; ?>
<?php endforeach; ?>
<?php wp_reset_query(); ?>
<?php endwhile; ?>
<?php else : ?>
Sorry, no posts matched your criteria.
<?php endif; ?>