获取头版 Wordpress 的 ID
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14148558/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get ID of front page Wordpress
提问by pbond
In the Wordpress admin settings>reading you can configure the 'frontpage displays as' as being a static page for the front page. Now I would like to retrieve the ID of the selected static page which is set to display as front page. I've tried Googling but to not much avail, thus I was wondering if there is a native function to retrieve this ID. (I don't feel like programming a workaround if there is a native direct function for this).
在 Wordpress 管理设置>阅读中,您可以将“首页显示为”配置为首页的静态页面。现在我想检索设置为显示为首页的所选静态页面的 ID。我试过谷歌搜索但没有多大用处,因此我想知道是否有一个本地函数来检索这个 ID。(如果有一个本机直接函数,我不想编写解决方法)。
回答by barakadam
The ID of the page used as static page is stored in the wp_options
WP table, as option_name
=page_on_front
and option_value
=ID of the page.
So if you want to retrieve this value, just use get_option('page_on_front')
.
用作静态页面的页面的 ID 存储在wp_options
WP 表中,作为页面的option_name
=page_on_front
和option_value
=ID。因此,如果您想检索此值,只需使用get_option('page_on_front')
.
回答by Felipe Alameda A
Here is an idea:
这是一个想法:
Get the page by Title first
先按标题获取页面
$Page = get_page_by_title( 'test' );
Then, get the ID like this
然后,像这样获取ID
echo $Page->ID . "<br /><br />";
回答by user2740280
The easiest way to see the page_id of the static page is to change the static page to another page and then go to Pages and click on the old page. The page_id is displayed in the Permalink above the edit area. After you see the page_id you can change the static page to the old one. The Permalink for the static page does not show the page_id but for all other pages it does.
查看静态页面的page_id最简单的方法是将静态页面改为另一个页面,然后进入Pages,点击旧页面。page_id 显示在编辑区域上方的固定链接中。看到 page_id 后,您可以将静态页面更改为旧页面。静态页面的永久链接不显示 page_id,但它显示所有其他页面。
回答by Bram
I was looking for the solution where you select a page as placeholder for the blog archive.
我一直在寻找解决方案,您可以选择一个页面作为博客存档的占位符。
You can do the same, but then query for 'page_for_posts' instead of 'page_on_front'. So:
您可以执行相同的操作,然后查询“page_for_posts”而不是“page_on_front”。所以:
$pageID = get_option('page_for_posts');
does the trick for that situation.
对那种情况有诀窍。