什麼,我試圖做的是運行我的索引頁面上有兩個獨立的迴路中的WordPress:WordPress的兩個循環的指數
一個不具有類職位5
而且
一說只有類別5
我一直以接近正確的結果結束,但第一個循環顯示我想要在第二個循環(這使我感到困惑)和一堆其他異常。
下面是代碼:
循環1:
<?php $blogPreview = new WP_Query('cat=-5'); ?>
<?php if ($blogPreview->have_posts()) : ?>
<?php while ($blogPreview->have_posts()) : $blogPreview->the_post(); ?>
<?php the_post(); ?>
<?php get_template_part('content-index', get_post_format()); ?>
<?php endwhile; ?>
<?php else : ?>
Sorry, but there are currently no posts in the blog!
<?php endif; ?>
<?php wp_reset_query(); ?>
循環2(稍低於在我的標記環1):
<?php $testimonials = new WP_Query('cat=5'); ?>
<?php if ($testimonials->have_posts()) : ?>
<?php while ($testimonials->have_posts()) : $testimonials->the_post(); ?>
<?php the_post(); ?>
<?php get_template_part('content-index-testimonials', get_post_format()); ?>
<?php endwhile; ?>
<?php else : ?>
Sorry, but there are currently no posts in the blog!
<?php endif; ?>
<?php wp_reset_query(); ?>
任何想法?在此先感謝
好吧,以便通過從循環中刪除「the_post()」來修復。
現在我不能排除此類別爲我的生活,我已經嘗試了所有的以下內容:
<?php $blogPreview = new WP_Query('cat=-5'); ?>
<?php $blogPreview = new WP_Query(array('category__not_in'=>5)); ?>
<?php $blogPreview = new WP_Query('category__not_in'=>array(5)); ?>
都未能做到這一點。
好吧所以原來的問題是固定的,但現在我不能爲我的生命排除類別,編輯主哨,以顯示新的問題 – BinarySolo00100 2012-02-29 16:43:40
感謝您接受我的答案。至於編輯,可能值得提出一個新問題,以免兩個問題混淆。對於它的價值,我看不出你嘗試過的第一條線有什麼問題。對於第二個和第三個,您可能需要'array()'兩次,所以'$ blogPreview = new WP_Query(array('category__not_in'=> array(5)));'。無論如何,這就是我讀[codex](http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters)的方式。 – Hobo 2012-02-29 17:55:18