确定页面是否为帖子页面
5 个回答
- 投票数
-
- 2011-04-14
is_home()
会检查"帖子页面",尽管函数名称有些混乱.is_home()
checks for the "Posts Page", despite the somewhat confusing function name.-
谢谢,我以为我检查了全部,但我想不是...thanks, i thought i checked them all, but i guess not...
- 0
- 2011-04-14
- mike
-
$ wp_query->is_posts_page呢?What about `$wp_query->is_posts_page`?
- 3
- 2013-05-15
- Weston Ruter
-
@WestonRuter对问题有正确的答案.@WestonRuter has the correct answer to the question.
- 0
- 2017-01-19
- The J
-
- 2015-09-13
Wordpress带有7种主要模板页面类型,可以通过这种方式确定
if ( is_main_query() ) { // Error if ( is_404() ) { ; } // Front page if ( is_front_page() ) { ; } // Archive if ( is_archive() ) { ; } // Comments popup if ( is_comments_popup() ) { ; } // Search if ( is_search() ) { ; } // Singular if ( is_singular() ) { ; } // Home - the blog page if ( is_home() ) { ; } }
is_home告诉您,您拥有博客页面.
Wordpress comes with 7 primary template page types, which can be determined on this way
if ( is_main_query() ) { // Error if ( is_404() ) { ; } // Front page if ( is_front_page() ) { ; } // Archive if ( is_archive() ) { ; } // Comments popup if ( is_comments_popup() ) { ; } // Search if ( is_search() ) { ; } // Singular if ( is_singular() ) { ; } // Home - the blog page if ( is_home() ) { ; } }
is_home tells to you, that you have the blog page.
-
- 2011-04-14
"帖子页面"通常是以下内容的存档:
- 一个类别的帖子
- 标签的帖子
- 日期(年,月...)的帖子
- 主要档案室的帖子
这些条件中的每一个都可以通过许多条件标签之一进行检查,例如
is_category() is_tag() is_date() is_archive()
等等.为了获得更好的理解,请转至法典 http://codex.wordpress.org/Conditional_Tags >"Posts page" is usually an archive of:
- posts of a category
- posts of a tag
- posts of a date ( year, month...)
- posts of main archive
Each one of these can be checked by a one of the many conditional tags like
is_category() is_tag() is_date() is_archive()
And so many more. To get a better understanding head over to the codex http://codex.wordpress.org/Conditional_Tags -
- 2018-01-10
首先检查博客相关内容,例如作者,标签,帖子类型
function is_blog () { global $post; $posttype = get_post_type($post ); return ( ((is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag())) && ( $posttype == 'post') ) ? true : false ; }
现在检查并返回您想要的东西
function check_post_type(){ $postType; if (is_blog()) { $postType = 'I am post'; } else { $postType = 'I am page'; }; return $postType; }
像老板一样使用它
<?php echo check_post_type();?>
感谢韦斯老板
First check the blogs related things like author, tag, post type
function is_blog () { global $post; $posttype = get_post_type($post ); return ( ((is_archive()) || (is_author()) || (is_category()) || (is_home()) || (is_single()) || (is_tag())) && ( $posttype == 'post') ) ? true : false ; }
Now check and return something which you want to have
function check_post_type(){ $postType; if (is_blog()) { $postType = 'I am post'; } else { $postType = 'I am page'; }; return $postType; }
Use it like Boss
<?php echo check_post_type();?>
Thanks to Wes Bos
-
- 2019-03-10
TL; DR
案例A .不需要在主模板文件(index.php)中确定它,因为它是它的默认模板 [1] .
案例B .要在页面模板(例如:page.php)中确定它,只需像这样检查它即可:
get_option( 'page_for_posts' ) == get_the_ID()
详细信息
我从字面上去挖掘源代码 [2] 只是为了知道wordpress如何检查值.事实证明,它使用语句
get_option( 'page_for_posts' )
来了解帖子页面中所选值的帖子ID.因此,为此,没有类似于
is_front_page()
的正式检查器功能.只要您知道所选页面的ID,就可以将其用于检查过程.
参考文献
-
WordPress Codex,主题开发, codex.wordpress.org/Theme_Development
-
设置的源代码› 阅读设置,github.com/WordPress/.../wp-admin/options-reading.php
TL;DR
Case A. There is no need to determine it inside the main template file (index.php) because it is the default template for it[1].
Case B. To determine it inside a page template (ex: page.php), simply check it like so:
get_option( 'page_for_posts' ) == get_the_ID()
Details
I literally went digging the source-code[2] of it just to be able to know how wordpress does the checking of the value. It turns out, it is using the statement
get_option( 'page_for_posts' )
to know the post ID of the selected value of the Posts page.So yeah, for this purpose, there is no such official checker function that is similar to
is_front_page()
.As long as you know the ID of the page that you've selected then you can use it for the checking process.
References
WordPress Codex, Theme Development, codex.wordpress.org/Theme_Development
Source-code of Settings › Reading Settings, github.com/WordPress/.../wp-admin/options-reading.php
在阅读设置页面上,您可以设置"首页"和"帖子页面".您可以检查当前页面
is_front_page();
"帖子页面"是否具有类似的功能.我注意到
is_page();
不适用于此特殊页面.谢谢