Breadcrumbs

How do I get Breadcrumbs to show up on pages like the product list, the shipping, the checkout, etc?

Pretty far along, I got Order Status and Cart working, and other things, but not to well.. would love to share code and get an awesome addition posted..

  • nickrosener

    Well.. We are going to update it, I saw many of the fixes, but I did not see an update that sounded like it would change the mp_product_list template, i.e. would not effect Framemarket with GridMarket child theme, and how it behaves when it calls various functions via php. I tried the breadcrumbs for everyone. In fact, I updated it with much information on what is missing. If I am mistaken and there is something that can be done (updating MarketPress, Discovering how to call each and every page individual via php if is.. ex: if is product list if is order status etc). Heres my code so far.. its OKAY, gets alot of areas, but not exactly the way I want, and not on product list page:

    function the_breadcrumb() {
    if ( 'product' == get_post_type() ){
    if (!is_front_page()) {
    		echo '<a href="Main Site Link">Main Store Name</a> > <a href="';
    		echo get_option('home');
    		echo '">';
    		bloginfo('name');
    		echo "</a> > ";
    		if (is_category() || is_single()) {
    			$ID = $wp_query->post->ID;
    			$categoria = mp_category_list($ID);
    			echo $categoria;
    			echo ' >';
    			if (is_single()) {
    				echo '<a href="';
    				echo get_permalink();
    				echo '">';
    				the_title();
    				echo '</a>';
    			}
    		} elseif (is_category() || !is_single()) {
    			$ID = $wp_query->post->ID;
    			$categoria = mp_category_list($ID);
    			echo $categoria;
    		} elseif (is_page()) {
    			echo '<a href="';
    			echo get_permalink();
    			echo '">';
    			the_title();
    			echo '</a>';
    		}
    }
    }elseif ( 'product' !== get_post_type() ){
    global $wp_query, $mp;
    //Variable (symbol >> encoded) and can be styled separately.
        //Use >> for different level categories (parent >> child >> grandchild)
                $delimiter = '<span class="delimiter"> > </span>';
        //Use bullets for same level categories ( parent . parent )
        $delimiter1 = '<span class="delimiter1"> - </span>';
    
        //text link for the 'Home' page
                $main = 'Home';
        //Display only the first 30 characters of the post title.
                $maxLength= 30;
    
        //variable for archived year
        $arc_year = get_the_time('Y');
        //variable for archived month
        $arc_month = get_the_time('F');
        //variables for archived day number + full
        $arc_day = get_the_time('d');
        $arc_day_full = get_the_time('l');  
    
        //variable for the URL for the Year
        $url_year = get_year_link($arc_year);
        //variable for the URL for the Month
        $url_month = get_month_link($arc_year,$arc_month);
    
        /*is_front_page(): If the front of the site is displayed, whether it is posts or a Page. This is true
        when the main blog page is being displayed and the 'Settings > Reading ->Front page displays'
        is set to "Your latest posts", or when 'Settings > Reading ->Front page displays' is set to
        "A static page" and the "Front Page" value is the current Page being displayed. In this case
        no need to add breadcrumb navigation. is_home() is a subset of is_front_page() */
    
        //Check if NOT the front page (whether your latest posts or a static page) is displayed. Then add breadcrumb trail.
        if (!is_front_page()) {
            //If Breadcrump exists, wrap it up in a div container for styling.
            //You need to define the breadcrumb class in CSS file.
    
            //global WordPress variable $post. Needed to display multi-page navigations.
            global $post, $cat;
            //A safe way of getting values for a named option from the options database table.
            $homeLink = get_option('home'); //same as: $homeLink = get_bloginfo('url');
            //If you don't like "You are here:", just remove it.
    		echo '<a href="Main Site Link">Main Site</a> > <a href="';
    		echo get_option('home');
    		echo '">';
    		bloginfo('name');
    		echo '</a>' . $delimiter;     
    
            //Display breadcrumb for single post
            if (is_single()) { //check if any single post is being displayed.
                //Returns an array of objects, one object for each category assigned to the post.
                //This code does not work well (wrong delimiters) if a single post is listed
                //at the same time in a top category AND in a sub-category. But this is highly unlikely.
                $category = get_the_category();
                $num_cat = count($category); //counts the number of categories the post is listed in.
    
                //If you have a single post assigned to one category.
                //If you don't set a post to a category, WordPress will assign it a default category.
                if ($num_cat <=1)  //I put less or equal than 1 just in case the variable is not set (a catch all).
                {
                    echo get_category_parents($category[0],  true,' ' . $delimiter . ' ');
                    //Display the full post title.
                    echo ' ' . get_the_title();
                }
                //then the post is listed in more than 1 category.
                else {
                    //Put bullets between categories, since they are at the same level in the hierarchy.
                    echo the_category( $delimiter1, multiple);
                        //Display partial post title, in order to save space.
                        if (strlen(get_the_title()) >= $maxLength) { //If the title is long, then don't display it all.
                            echo ' ' . $delimiter . trim(substr(get_the_title(), 0, $maxLength)) . ' ...';
                        }
                        else { //the title is short, display all post title.
                            echo ' ' . $delimiter . get_the_title();
                        }
                }
            }
            //Display breadcrumb for category and sub-category archive
            elseif (is_category()) { //Check if Category archive page is being displayed.
                //returns the category title for the current page.
                //If it is a subcategory, it will display the full path to the subcategory.
                //Returns the parent categories of the current category with links separated by '»'
                echo get_category_parents($cat, true,' ' . $delimiter . ' ');
            }
            //Display breadcrumb for tag archive
            elseif ( is_tag() ) { //Check if a Tag archive page is being displayed.
                //returns the current tag title for the current page.
                echo 'Posts Tagged: "' . single_tag_title("", false) . '"';
            }
            //Display breadcrumb for calendar (day, month, year) archive
            elseif ( is_day()) { //Check if the page is a date (day) based archive page.
                echo '<a href="' . $url_year . '">' . $arc_year . '</a> ' . $delimiter . ' ';
                echo '<a href="' . $url_month . '">' . $arc_month . '</a> ' . $delimiter . $arc_day . ' (' . $arc_day_full . ')';
            }
            elseif ( is_month() ) {  //Check if the page is a date (month) based archive page.
                echo '<a href="' . $url_year . '">' . $arc_year . '</a> ' . $delimiter . $arc_month;
            }
            elseif ( is_year() ) {  //Check if the page is a date (year) based archive page.
                echo $arc_year;
            }
            //Display breadcrumb for search result page
            elseif ( is_search() ) {  //Check if search result page archive is being displayed.
                echo 'Search Results for: "' . get_search_query() . '"';
            }
            //Display breadcrumb for top-level pages (top-level menu)
            elseif ( is_page() && !$post->post_parent ) { //Check if this is a top Level page being displayed.
                echo get_the_title();
    global $wp_query;
            if ($wp_query->query_vars['checkoutstep'] == 'checkout'){
    echo '<a href="';
    echo get_option('home');
    echo '/store/">Store</a> > <a href="';
    echo get_option('home');
    echo '/store/products/">Products</a>';
     }
    if ($wp_query->query_vars['pagename'] == 'cart'){
    echo '<a href="';
    echo get_option('home');
    echo '/store/">Store</a> > <a href="';
    echo get_option('home');
    echo '/store/shopping-cart/">Cart</a>';
     }
    if ($wp_query->query_vars['pagename'] == 'orderstatus'){
    echo '<a href="';
    echo get_option('home');
    echo '/store/">Store</a> > <a href="';
    echo get_option('home');
    echo '/store/order-status/">Order Status</a>';
    }
            //Display breadcrumb trail for multi-level subpages (multi-level submenus)
            } elseif ( is_page() && $post->post_parent ) {  //Check if this is a subpage (submenu) being displayed.
                //get the ancestor of the current page/post_id, with the numeric ID
                //of the current post as the argument.
                //get_post_ancestors() returns an indexed array containing the list of all the parent categories.
                $post_array = get_post_ancestors($post);
    
                //Sorts in descending order by key, since the array is from top category to bottom.
                krsort($post_array); 
    
                //Loop through every post id which we pass as an argument to the get_post() function.
                //$post_ids contains a lot of info about the post, but we only need the title.
                foreach($post_array as $key=>$postid){
                    //returns the object $post_ids
                    $post_ids = get_post($postid);
                    //returns the name of the currently created objects
                    $title = $post_ids->post_title;
                    //Create the permalink of $post_ids
                    echo '<a href="' . get_permalink($post_ids) . '">' . $title . '</a>' . $delimiter;
                }
                the_title(); //returns the title of the current page.
            }
            //Display breadcrumb for author archive
            elseif ( is_author() ) {//Check if an Author archive page is being displayed.
                global $author;
                //returns the user's data, where it can be retrieved using member variables.
                $user_info = get_userdata($author);
                echo  'Archived Article(s) by Author: ' . $user_info->display_name ;
            }
            //Display breadcrumb for 404 Error
            elseif ( is_404() ) {//checks if 404 error is being displayed
                echo  'Error 404 - Not Found.';
            }
            else {
                //All other cases that I missed. No Breadcrumb trail.
            }
        }elseif (is_front_page){
    	echo '<a href="Main Site Link">Main Site</a> > <a href="';
    		echo get_option('home');
    		echo '">';
    		bloginfo('name');
    		echo "</a>";
    }
    }
    }

    In truth what I am doing is piggy backing other ideas. What I am doing is saying if it is the post type products do breadcrumbs one way, if not do it the other, and if the marketpress page acts like a normal page i account for that in the other-than-products-post-type way (second half of above function). from there I have gotten the order status and cart page to say there names by adding global $wp_query, $mp; and then if ($wp_query->query_vars['pagename'] == 'cart'), etc. But I hard coded the link to the default so that also needs to change based on the marketpress url settings for the cart ETC. It would be nice to either have a set breadcrumb or a manual of how to do conditional tags with Marketpress. Bonus for how to replicate how marketpress figures out the new url for store, products, cart ETC. (found the function but am unsure how to adapt it for this code, repeat and rename it? or something in between)

    This is one of many issues with the site at present concerning MarketPress for WPMU and member sites. There are SEVERAL other bugs I am experiencing -> ex: search and form submits go to unusual url string for main site FROM member site, NOT even a 404.

    Thanks for any advice in these highly custom areas!!

  • nickrosener

    Basically I think we got it to work on every page except for Products and Store, and we were unable to make the orders dynamic, to the setting of the page they choose.. for example making orders page say "My Store -> Your Store -> Orders" with the linking going to where ever you set orders to be besides "/orders/", also we were unable to make subsequent pages of the checkout process say something different then the cart..

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.