从永久链接获得postid

时间:2011-03-09 16:38:38

标签: php wordpress wordpress-theming

如何从网址获取帖子ID。例如,我打开了页面mysiteurl/mypagename 在页面处理程序中我需要获得帖子ID。

如果我的默认固定链接比我从名称 /?p = 123 获得的默认固定链接,但我有非默认值,所以我无法从名称中获取帖子ID

像UNPERMALINK这样的东西,因为它与the_permalink相反。

NB - 我没有循环。

1 个答案:

答案 0 :(得分:4)

假设你加载了wordpress框架,你可以使用url_to_postid() - 与get_permalink()相反:

<?php $postid = url_to_postid( $url ); ?> 

您的永久链接为$url

相关问题