WordPress.org

Make WordPress Core

Ticket #3566: post.php.diff

File post.php.diff, 1.6 KB (added by Huskey, 5 years ago)
  • .php

    old new  
    19891989} 
    19901990 
    19911991/** 
     1992 * Retrieve page parents with separator. 
     1993 * 
     1994 * @since 2.8 
     1995 * 
     1996 * @param int $id Page ID. 
     1997 * @param bool $link Optional, default is false. Whether to format with link. 
     1998 * @param string $separator Optional, default is '/'. How to separate pages. 
     1999 * @param bool $nicename Optional, default is false. Whether to use nice name for display. 
     2000 * @param array $visited Optional. Already linked to pages to prevent duplicates. 
     2001 * @return string 
     2002 */ 
     2003function get_page_parents( $id, $link = false, $separator = '/', $nicename = false, $visited = array() ) { 
     2004        $chain = ''; 
     2005        $parent = &get_page( $id ); 
     2006        if ( is_wp_error( $parent ) ) 
     2007                return $parent; 
     2008 
     2009        if ( $nicename ) 
     2010                $name = $parent->post_name; 
     2011        else 
     2012                $name = $parent->post_title; 
     2013 
     2014        if ( $parent->post_parent && ( $parent->post_parent != $parent->ID ) && !in_array( $parent->post_parent, $visited ) ) { 
     2015                $visited[] = $parent->post_parent; 
     2016                $chain .= get_page_parents( $parent->post_parent, $link, $separator, $nicename, $visited ); 
     2017        } 
     2018 
     2019        if ( $link ) 
     2020                $chain .= '<a href="' . get_page_link( $parent->ID ) . '" title="' . $parent->post_title . '">'.$name.'</a>' . $separator; 
     2021        else 
     2022                $chain .= $name.$separator; 
     2023        return $chain; 
     2024} 
     2025 
     2026/** 
    19922027 * Order the pages with children under parents in a flat list. 
    19932028 * 
    19942029 * Fetches the pages returned as a FLAT list, but arranged in order of their