admin管理员组文章数量:1122846
I like to get the ID of the selected front page.
My page uses an Template for that page.
I've read about get_option('page_on_front')
, but this didn't work for me.
Is there any function to get this ID?
I like to get the ID of the selected front page.
My page uses an Template for that page.
I've read about get_option('page_on_front')
, but this didn't work for me.
Is there any function to get this ID?
Share Improve this question asked Jun 11, 2014 at 12:23 RinkyyRinkyy 131 silver badge4 bronze badges 5 |4 Answers
Reset to default 2This should do the trick.
global $wp_query;
$post = $wp_query->get_queried_object();
$post->ID;
This'll give you the ID for each page you're on.
get_option( 'page_on_front' )
should've worked though.
You could either go into your Dashboard > 'Pages' and then hover over the page that is using the front page template and hover over the title - on the bottom left of your screen you will see a string of information like this:
http://yourdomain.com/wp-admin/post.php?post=724&action=edit
Post=724, that part will be the ID of that page.
Or programmatically you could use this function and pass the slug of this page using the front page template:
function royal_get_id($page_slug) {
$page = get_page_by_path($page_slug);
if ($page) {
return $page->ID;
} else {
return null;
}
}
$value = royal_get_id('your-homepage-slug');
echo $value;
What you doing is correct then, just store it in a variable to use as you need to.
Also make sure you have set the page as the front page in your dashboard under 'Settings' > Reading or else this value will be empty as it is not set.
$front_id = get_option('page_on_front');
echo $front_id;
you can also get the global post and fetch its ID inside a loop - that way you get the ID of each page - as in WordPress all pages are posts.
global $post;
$post->ID
本文标签: frontpageID of FrontPage
版权声明:本文标题:frontpage - ID of Front-Page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736295485a1929580.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
Settings -> Reading
admin page, is "A static page" selected on "Front page displays", and is a page selected in the "Front page" dropdown? – engelen Commented Jun 11, 2014 at 12:52