wordpress搜索结果排除某个分类如何操作

  我们知道wordpress的搜索结果页search.php和分类页category.php是一样的,但是客户的网站是功能比较多的系统,有新闻又有产品,如果搜索结果只想展示产品要如何操作呢?随ytkah一起来看看吧

  假设新闻分类id为1,3,4,排除调用这三个分类id的代码如下

<?php if ( have_posts() ) : query_posts($query_string .'&cat=-1,-3,-4'); while ( have_posts() ) : the_post(); ?>
                                <div class="item col-xs-12 col-sm-6 col-md-4"><a
                                            href="<?php the_permalink(); ?>">
                                        <?php if (get_field('pimg01')): ?>
                                            <img src="<?php the_field('pimg01'); ?>"
                                                 alt="<?php the_title(); ?>"/>
                                        <?php endif; ?>
                                        <div class="text"><p><?php the_title(); ?></p></div>
                                    </a>
                                </div>
                            <?php endwhile; ?>

                                <?php the_posts_pagination(array('mid_size' => 2, 'prev_text' => __('Prev', 'textdomain'), 'next_text' => __('Next', 'textdomain'),)); ?>

                            <?php else : ?>
                                no products!
                            <?php endif; ?>

  

posted @ 2019-11-11 14:52  ytkah  阅读(599)  评论(0编辑  收藏  举报
IPO发家故事 网址导航 gg N / G Sitemap

部分内容来源于网络,如有版权问题请联系删除