且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在wordpress中检测主页有哪些不同的方法?

更新时间:2023-12-04 19:21:40

is_front_page() 就是你想要的.

我假设,根据 wp-admin 中的设置,is_home() 不起作用,您的主页是静态的.

is_home() 在您的主要博客页面上返回 true,而 is_front_page() 在任何被定义为首页的页面上返回 true,无论是否为 Feed.>

来自法典:

此条件标签检查主页是帖子还是页面.这是一个布尔函数,意味着它返回 TRUE 或 FALSE.当显示主博客页面并且设置->阅读->前页显示设置为您的最新帖子"时,或设置为静态页面"且前页"值为正在显示的当前页面.

What are the different ways to detect wordpress homepage

except is_front_page() and is_home()

Thanks

is_front_page() is what you want.

I assume, by the fact that is_home() is not working, that your home page is static, according to the settings in wp-admin.

is_home() returns true on your main blog page whereas is_front_page() returns true on which ever page is defined as your front page, feed or not.

From codex:

This Conditional Tag checks if the main page is a posts or a Page. This is a boolean function, meaning it returns either TRUE or FALSE. It returns TRUE when the main blog page is being displayed and the Settings->Reading->Front page displays is set to "Your latest posts", or when is set to "A static page" and the "Front Page" value is the current Page being displayed.