wordpress模板制作的过程中有时会用到获取父页面的ID,下面是wordpress获取父页面的2种方法。

方法一

global $post;
$id = $post -> ID;
$parent = get_post_ancestors($post -> ID);
print_r($parent);

方法二

global $post;
$parent_id = $post -> post_parent;
echo $parent_id;

最后更新日期: 2024:1:5:16:24