• Resolved eian00

    (@eian00)


    Hello,

    What I was trying to do is to display a current location menu, to display as links all the parent pages of the current page, from the first parent until the current page name, ex;

    Home/Laboratory/Laboratory Name/Projects/The Project

    Thank you

Viewing 2 replies - 1 through 2 (of 2 total)
  • The $post->ancestor will hold an array of a particular posts ‘parents’.

    Related plugin:
    http://wordpress.org/extend/plugins/breadcrumbs/

    Thread Starter eian00

    (@eian00)

    Thanks,

    I found this function that makes the work ;

    function get_breadcrumbs()
    {
    	global $wp_query;
    
    	if ( !is_home() ){
    
    		// Start the UL
    		echo '<ul class="breadcrumbs">';
    		// Add the Home link
    		echo '<li><a href="'. get_settings('home') .'">'. get_bloginfo('name') .'</a></li>';
    
    		if ( is_category() )
    		{
    			$catTitle = single_cat_title( "", false );
    			$cat = get_cat_ID( $catTitle );
    			echo "<li> &raquo; ". get_category_parents( $cat, TRUE, " &raquo; " ) ."</li>";
    		}
    		elseif ( is_archive() && !is_category() )
    		{
    			echo "<li> &raquo; Archives</li>";
    		}
    		elseif ( is_search() ) {
    
    			echo "<li> &raquo; Search Results</li>";
    		}
    		elseif ( is_404() )
    		{
    			echo "<li> &raquo; 404 Not Found</li>";
    		}
    		elseif ( is_single() )
    		{
    			$category = get_the_category();
    			$category_id = get_cat_ID( $category[0]->cat_name );
    
    			echo '<li> &raquo; '. get_category_parents( $category_id, TRUE, " &raquo;</li><li> " );
    			echo the_title('','', FALSE) ."</li>";
    		}
    		elseif ( is_page() )
    		{
    			$post = $wp_query->get_queried_object();
    
    			if ( $post->post_parent == 0 ){
    
    				echo "<li> &raquo; ".the_title('','', FALSE)."</li>";
    
    			} else {
    				/* Kindly borrowed and adapted from Breadcrumb Titles For Pages plugin
    				http://wordpress.org/extend/plugins/page-breadcrumbs-for-wptitle/ */
    				$title = the_title('','', FALSE);
    				$prefix = "</li><li> &raquo; ";
    
    				$seplocation = ( $prefix === substr( $title, strlen( $prefix ) * -1 ) ) ? 'right' : 'left';
    
    				$ancestors = array_reverse( $post->ancestors );
    				$ancestors[] = $post->ID;
    
    				$titles = array();
    				foreach ( $ancestors as $ancestor ){
    					if( $ancestor != end($ancestors) ){
    						$titles[] = '<a href="'. get_permalink($ancestor) .'">'. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .'</a>';
    					} else {
    						$titles[] = strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) );
    					}
    				}
    
    				$title = implode( $prefix, $titles );
    
    				if ( $seplocation == 'right' )
    					$title = $title . $prefix;
    				else
    					$title = $prefix . $title;
    
    				echo $title;
    			}
    		}
    
    		// End the UL
    		echo "</ul>";
    	}
    }

    And then you call the breadcrumbs with;

    <?php get_breadcrumbs(); ?>

    The function works really fine on the WordPress 2.8 version, but as on the second site I am working on, I’m limited on the version 2.5, and I am getting the following error;

    Warning: array_reverse() [function.array-reverse]: The argument should be an array in /usr/share/wordpress/wp-content/themes/cim/functions.php on line 470

    Line 470 sounds: $ancestors = array_reverse( $post->ancestors );

    What is the problem?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to generate the root of the current page?’ is closed to new replies.