我们知道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; ?>

  

相关文章:

  • 2022-12-23
  • 2021-11-29
  • 2022-12-23
  • 2021-08-27
  • 2022-01-28
  • 2021-06-06
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-24
  • 2021-12-24
  • 2022-12-23
  • 2021-07-09
  • 2021-09-07
  • 2021-04-14
相关资源
相似解决方案