WordPress:如何检查搜索结果是否是页面的帖子?

在我的搜索档案视图中, 某些结果将是帖子, 而某些结果将是页面。我想在模板中为帖子和页面提供不同的视觉处理。

我试过使用if(is_post())和if(is_page())没有运气。我该怎么做?


#1


is_page()取决于请求如何映射到主要查询变量, 因此你可以改为在循环内检查帖子类型:

the_title();

$post_type = get_post_type();

if( 'post' === $post_type ) {

    // it is post, and style it like the way you need

} elseif ( 'page' === $post_type ) {

   // it is page

}

来源:

https://www.srcmini02.com/66149.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_40621.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?