• Resolved allencg

    (@allencg)


    Hello

    I have been trying with this code to get the breadcrumbs to always show sufficient levels of breadcrumbs depending on the number of parents there are. So if the page is 4 levels deep it should show four links. Trouble is with this code I can only get the current page and its first parent. If there is a third level I have been adding it manually into the template, but is there a clean way to do this automatically. Like with <?php while or something. I am an extreme novice, so do give me the full code if you can and I can back engineer it to work out the fix but more importantly know how to apply it.

    <p id="bread"><span itemscope itemtype="https://data-vocabulary.org/Breadcrumb">
    				<span class="breadcrumb"><a href="<?php echo get_permalink(28); ?>" itemprop="url"><span itemprop="title">Home</span></a></span> &raquo;</span>      
    
          <span itemscope itemtype="https://data-vocabulary.org/Breadcrumb">
          <span class="breadcrumb"><?php
    // if there is a parent, display the link
    $parent_title = get_the_title( $post->post_parent );
    if ( $parent_title != the_title( ' ', ' ', false ) ) {
    	echo '<a href="' . get_permalink( $post->post_parent ) . '" itemprop="url" title="' . $parent_title . '">' . $parent_title . '</a>';
    }
    // then go on to the current page link
    ?></span> &raquo;</span>
    
    			<span class="breadcrumb" itemscope itemtype="https://data-vocabulary.org/Breadcrumb">
                <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" itemprop="url"><span itemprop="title"><?php the_title(); ?></span></a></span></p>
Viewing 1 replies (of 1 total)
  • Thread Starter allencg

    (@allencg)

    I managed a word-around by installing the Yoast breadcrumbs and it works a treat. No point reinventing the wheel.

Viewing 1 replies (of 1 total)
  • The topic ‘Automatic X level deep breadcrumbs’ is closed to new replies.