我正在创建搜索结果页面,并且我试图排除特定的帖子格式。我发现了这个查询,但我不知道如何使帖子循环工作,我甚至不知道代码。并且,我不知道如何在search.php上找到404错误。
这是代码
<?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 );
?>
我第一次尝试了一些并且工作得很好,但如果我设置了#34;每页4个帖子&#34;它会计算所有格式的帖子,如果搜索结果上的标准帖子应该是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; ?>
答案 0 :(得分: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(); ?>