This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jun 21st, 2012  |  syntax: None  |  size: 0.44 KB  |  views: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. if(!function_exists('get_post_top_ancestor_id')){
  2. /**
  3.  * Gets the id of the topmost ancestor of the current page. Returns the current
  4.  * page's id if there is no parent.
  5.  *
  6.  * @uses object $post
  7.  * @return int
  8.  */
  9. function get_post_top_ancestor_id(){
  10.     global $post;
  11.    
  12.     if($post->post_parent){
  13.         $ancestors = array_reverse(get_post_ancestors($post->ID));
  14.         return $ancestors[0];
  15.     }
  16.    
  17.     return $post->ID;
  18. }}
clone this paste RAW Paste Data