【问题标题】:Search only posts (not pages) in wordpress在 wordpress 中仅搜索帖子(而不是页面)
【发布时间】:2012-12-11 23:18:59
【问题描述】:

我希望 WP 搜索引擎只搜索帖子(现在它搜索帖子和页面) - 有人知道该怎么做吗?

【问题讨论】:

    标签: wordpress


    【解决方案1】:

    首先,在你主题的functions.php文件中,添加这个函数:

    function is_type_page() { // Check if the current post is a page
    global $post;
    
    if ($post->post_type == 'page') {
        return true;
    } else {
        return false;
    }
    

    }

    接下来,在主题的 search.php 文件中(显示搜索结果的位置,您希望在循环之后添加以下行。它应该如下所示:

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

    【讨论】:

      猜你喜欢
      • 2018-01-02
      • 2023-03-31
      • 2015-08-13
      • 1970-01-01
      • 2020-12-20
      • 2011-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多