如何在 Blogger 的搜索结果 'No posts matching the query' 中隐藏小部件?

How to Hide Widgets From search result 'No posts matching the query' in blogger?

我想在搜索结果“没有 post 匹配查询”页面中隐藏一些小部件。我使用了下面的代码,但它只适用于“显示 posts 按查询的相关性排序”页面。

<b:if cond='data:blog.searchQuery'>
      <style type='text/css'>
        div#HTML4{display:none !important;}
        div#HTML2{display:none !important;}
        div#FollowByEmail1{display:none !important;}
        div#HTML3{display:none !important;}
        div#HTML1{display:none !important;}
        </style>
    </b:if>

默认情况下,此代码将在每个搜索页面上运行,要使其在没有搜索结果时也能运行,请添加另一个条件以检查页面上的搜索结果数。

New Condition : When its a search page and there are no posts.

<b:if cond='data:blog.searchQuery and data:numPosts == 0'>
  <style type='text/css'>
    div#HTML4{display:none !important;}
    div#HTML2{display:none !important;}
    div#FollowByEmail1{display:none !important;}
    div#HTML3{display:none !important;}
    div#HTML1{display:none !important;}
  </style>
</b:if>

data:numPosts 仅在 main 部分有效,您必须在主要部分添加此代码。