• Hey Everyone!

    In a previous thread I was attempting to generate breadcrumbs for categories, sub-categories, and listings. Yoast’s SEO and other breadcrumb plugins wouldn’t work so I took it upon myself to give this awesome plugin some breadcrumbs!!! After working through the code I developed a solution. It was a little tricky but I got it to work!

    The following scripts are to be added to the category.php and single.php template files. Just make sure that you follow instructions on creating the LDD Directory Lite template directory in your WordPress theme.

    Add the following code to the category.php template file:

    <a href="link-to-directory-homepage">Page Name</a> //Change hyperlink href and anchor text to your preference
    <?php
    	$product_terms = wp_get_object_terms($post->ID, 'listing_category');
    	$subs = ldl_get_categories(get_queried_object()->term_id );
    	$termsCount = count($product_terms);
    	$catName = get_queried_object()->name;
    	if(($subs) || is_tax( 'listing_tag' )) {
    		echo '? '.get_queried_object()->name;
    	} else {
    		if(!empty($product_terms)){
    			if(!is_wp_error( $product_terms )){
    				$i = 0;
    				$e = 0;
    				foreach(array_reverse($product_terms) as $term){
    					if ($e != 0) {
    						$termName = $term->name;
    					}
    					$e++;
    				}
    				if($catName == $termName) {
    					foreach(array_reverse($product_terms) as $term){
    						if ($i != $termCount) {
    							echo ' ? '.$term->name.'';
    						} else {
    							echo '? <a href="'.get_term_link($term->slug, 'listing_category').'">'.$term->name.'</a>';
    						}
    						$i++;
    					}
    				} else {
    					foreach($product_terms as $term){
    						if ($i != $termCount) {
    							echo ' ? <a href="'.get_term_link($term->slug, 'listing_category').'">'.$term->name.'</a>';
    						} else {
    							echo ' ? '.$term->name.'';
    						}
    						$i++;
    					}
    				}
    			}
    		}
    	}
    ?>

    Add the following code to the single.php template file:

    <a href="link-to-directory-homepage">Page Name</a> $raquo; //Change hyperlink href and anchor text to your preference
    <?php
    	$product_terms = wp_get_object_terms($post->ID, 'listing_category');
    	$cat_terms = wp_get_object_terms($post->ID, 'listing_category');
    	if(!empty($product_terms)) {
    		if (!is_wp_error( $product_terms)) {
    			$e = 0;
    			foreach($product_terms as $term) {
    				if ($e == 0) {
    					// We have to figure out if the first item in the array is a parent category or not so make sure to
    					// replace my values (2,3,4,5) below with the ID's of your parent categories.
    					if(($term->ID == 2) || ($term->ID == 3) || ($term->ID == 4) || ($term->ID == 5)) {
    						foreach($cat_terms as $cat) {
    							echo '<a href="'.get_term_link($cat->slug, 'listing_category').'">'.$cat->name.'</a> ? ';
    						}
    					} else {
    						foreach(array_reverse($cat_terms) as $cat) {
    							echo '<a href="'.get_term_link($cat->slug, 'listing_category').'">'.$cat->name.'</a> ? ';
    						}
    					}
    					$e++;
    				}
    			}
    		}
    	}
    ?><?php the_title(); ?>

    Be sure to follow the few instructions that are commented out in the source codes!! Hope this helps ??

    https://www.ads-software.com/plugins/ldd-directory-lite/

  • The topic ‘Breadcrumbs for all!’ is closed to new replies.