admin管理员组文章数量:1415137
I'm new to wordpress and I'm following a tutorial right now but I don't understand wordpresses behaviour. I'm trying to change the title of a sidebar which lists the parentpage and it's childpages, this works fine but I don't understand why $parentID = wp_get_post_parent_id(get_the_ID()); echo get_permalink($parentID);
works even on the parent page, I echoed the result on the parent page and it returns 0 since the parent page doesnt have a parent, so why does this still work? Why does get_permalink(0)
get me to the parent page if I press the button on the parent page? It also gives me the Title even though it would be get_the_title(0)
I'm new to wordpress and I'm following a tutorial right now but I don't understand wordpresses behaviour. I'm trying to change the title of a sidebar which lists the parentpage and it's childpages, this works fine but I don't understand why $parentID = wp_get_post_parent_id(get_the_ID()); echo get_permalink($parentID);
works even on the parent page, I echoed the result on the parent page and it returns 0 since the parent page doesnt have a parent, so why does this still work? Why does get_permalink(0)
get me to the parent page if I press the button on the parent page? It also gives me the Title even though it would be get_the_title(0)
1 Answer
Reset to default 2If an ID is passed to get_the_title()
or get_permalink()
, they will use get_post()
internally to get a copy of the full post object with that ID. But if get_post()
is passed either nothing or a "falsy" value, like 0
, then it will return the current global $post
object. In the context of your code this is likely to be the current page.
So:
get_permalink( 0 );
Is equivalent to:
get_permalink( get_the_ID() );
Which is equivalent to:
get_permalink();
Because they are all referring to the current global $post
.
本文标签: permalinksReturn value of getpermalink(0) and getthetitle(0)
版权声明:本文标题:permalinks - Return value of get_permalink(0) and get_the_title(0) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745222453a2648456.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论