[wp-trac] Re: [WordPress Trac] #3566: Request for new function get_page_parents

WordPress Trac wp-trac at lists.automattic.com
Thu Nov 8 18:28:54 GMT 2007


#3566: Request for new function get_page_parents
-------------------------+--------------------------------------------------
 Reporter:  snakefoot    |        Owner:  anonymous
     Type:  enhancement  |       Status:  new      
 Priority:  normal       |    Milestone:  2.4      
Component:  General      |      Version:  2.1      
 Severity:  normal       |   Resolution:           
 Keywords:  has-patch    |  
-------------------------+--------------------------------------------------
Comment (by Huskey):

 Your solution has a bug and returns the page title for $nicename = TRUE
 and vice-versa, which is wrong. Also, it lacks the check for a valid page
 object returned. Here's the updated code:

 {{{
 function get_page_parents($id, $link = FALSE, $separator = '/', $nicename
 = FALSE) {
         $chain = '';
         $parent = &get_page($id);
         if ( is_wp_error( $parent ) )
                 return $parent;

         if ( $nicename )
                 $name = $parent->post_name;
         else
                 $name = $parent->post_title;

         if ( $parent->post_parent )
                 $chain .= get_page_parents($parent->post_parent, $link,
 $separator, $nicename);

         if ( $link )
                 $chain .= '<a href="' . get_page_link($parent->ID) . '"
 title="' . $parent->post_title . '">'.$name.'</a>' . $separator;
         else
                 $chain .= $name.$separator;
         return $chain;
 }
 }}}

-- 
Ticket URL: <http://trac.wordpress.org/ticket/3566#comment:6>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list