2016-02-27 45 views
0

我正在創建一個搜索結果頁面,我試圖排除特定的帖子格式。我發現這個查詢,但我不知道如何使後循環的作品,我甚至不知道代碼。而且,我不知道如何在404上找不到search.php。

這是代碼

<?php 
$args = array(
    'tax_query' => array(
    array(
     'taxonomy' => 'post_format', 
     'field' => 'slug', 
     'terms' => 'post-format-quote', 'post-format-video', 
     'operator' => 'NOT IN' 
    ) 
) 
); 
query_posts($args); 
?> 

我第一次嘗試的東西和工作正常,但如果我設置「每頁4後」,它計算所有的格式後,如果在搜索結果的標準帖子應該是3和1格式的帖子,它顯示3個標準帖子和一個空白空間。

<?php if (have_posts()) : ?> 
<?php while (have_posts()) : the_post(); ?> 

<?php if(get_post_format() == 'quote') : ?> 
<?php elseif(get_post_format() == 'link') : ?> 
<?php elseif(get_post_format() == 'video') : ?> 
<?php elseif(get_post_format() == 'image') : ?> 
<?php else : ?> 


post 

<?php endif; ?> 

<?php endwhile; else : ?> 
    <?php get_template_part('partials/content', 'none'); ?> 
<?php endif; ?> 
+1

也許是因爲當帖子格式爲報價時你什麼都不做?請發佈整個代碼,而不是它的一部分。 – Gal

回答

0

這是我的search.php的整個代碼。這是在搜索結果中不顯示其他格式的唯一方式。我只希望循環不會在結果中計算「其他格式文章」。我想每頁顯示4個結果,並且必須是4個標準帖子格式。

<?php 

get_header(); ?> 

<div id="content" class="site-content"> 


<div id="news-page"> 


<div class="right"> 


<?php get_sidebar(); ?> 
</div> 
<div class="left"> 

<div class="newstitle">RISULTATI</div> 

<?php if (have_posts()) : ?> 
<?php while (have_posts()) : the_post(); ?> 

<?php if(get_post_format() == 'quote') : ?> 
<?php elseif(get_post_format() == 'link') : ?> 
<?php elseif(get_post_format() == 'video') : ?> 
<?php elseif(get_post_format() == 'image') : ?> 
<?php else : ?> 

<a href="<?php the_permalink(); ?>" title="Leggi"> 

<div class="post"> 

<div class="data"> 
<span class="giorno"><?php the_time('j M Y') ?></span> <span class="commenti"><?php comments_number('0 commenti', '1 commento', '% commenti'); ?></span> 
</div> 

<div class="thumb"><?php if (has_post_thumbnail()) { the_post_thumbnail('news-page'); } ?></div> 
<div class="thumb-full"><?php if (has_post_thumbnail()) { the_post_thumbnail('news-page-full'); } ?></div> 

<div class="title"><?php echo get_the_title($post_id); ?></div> 

<div class="excerpt"><?php the_excerpt(); ?></div> 

<div class="diss"></div> 


<div style="position: absolute; z-index:999; bottom: 0; left: 0; font: normal 10px arial; padding: 3px;"> In <?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?></div> 


</div> 

</a> 



<?php endif; ?> 

<?php endwhile; else : ?> 
    <?php get_template_part('partials/content', 'none'); ?> 
<?php endif; ?> 
</div> 
</div> 


    </div><!-- #primary --> 

<?php get_footer(); ?> 
+0

wheres你的'query_posts()'函數調用? – Gal