0

Currently using the 'maisha' theme. Created custom page to display breadcrumbs for all pages, however, when a sidebar is not applied or turned 'on' in the widgets section, the breadcrumbs disappear. This page situation happens rarely, but in the instance that there is not a need for a sidebar, I would like to have the breadcrumbs. There is multiple parents, each with children, and grandchildren.

Code:

<?php if ( is_active_sidebar( 'sidebar-5' ) ) : ?>
<div class="hfeed site default-page">
    <div class="content site-content">
        <main class="main site-main" role="main">
            <div class="single-themes-page clear news">
                <div class="breadcrumbs" typeof="BreadcrumbList" vocab="https://schema.org/">
                    <?php 
                        if(function_exists('bcn_display'))
                            {
                                    bcn_display();
                            }
                        ?>
                </div>
                    <div class="two_third">
                    <div id="primary" class="content-area">
                      <?php
                          // Start the loop.
                          while ( have_posts() ) : the_post();

                              // Include the page content template.
                              get_template_part( 'content', 'page' );

                              // If comments are open or we have at least one comment, load up the comment template.
                              if ( comments_open() || get_comments_number() ) :
                                  comments_template();
                              endif;

                          // End the loop.
                          endwhile;
                      ?>
                    </div>
                    </div>
                    <div class="one_third lastcolumn">
                    <div id="sidebar" class="sidebar">
                    <?php get_sidebar( 'additional-two' ); ?>
                    </div><!-- .sidebar -->
                </div>
            </div>
        </main><!-- .content-area -->
    </div><!-- .site-content -->
</div><!-- .site -->
<?php else: ?>
<div class="hfeed site default-page">
    <div class="content site-content">
        <main class="main site-main" role="main">
            <div class="single-themes-page clear news">
            <div class="breadcrumbs" typeof="BreadcrumbList" vocab="https://schema.org/">
                <?php
                    if(function_exists('bcn_display'))
                        {
                                bcn_display();
                        }
                    ?>
                </div>
                <div id="primary" class="content-area">
                    <?php
                        // Start the loop.
                        while ( have_posts() ) : the_post();

                            // Include the page content template.
                            get_template_part( 'content', 'page' );

                            // If comments are open or we have at least one comment, load up the comment template.
                            if ( comments_open() || get_comments_number() ) :
                                comments_template();
                            endif;

                        // End the loop.
                        endwhile;
                    ?>
                </div>
            </div>
        </main><!-- .content-area -->
    </div><!-- .site-content -->
</div><!-- .site -->
<?php endif; ?>

In the above code, I have applied this code twice:

<div class="breadcrumbs" typeof="BreadcrumbList" vocab="https://schema.org/">
     <?php 
          if(function_exists('bcn_display'))
            {
                bcn_display();
            }
      ?>
</div>

Once in the beginning of the if statement, and again in the else statement. However, the breadcrumbs does not appear. Am I doing this incorrectly? Is the logic incorrect, or am I misunderstanding the code?

  • Could it be a styling issue? If you view your page source on a page with this template that has no sidebar, is the <div class="breadcrumbs"> there with its content? – WebElaine Aug 22 '18 at 15:10
  • @WebElaine No, it does not appear in the source. – kdickins Aug 22 '18 at 15:24
  • Then it sounds like you may be working on the wrong template. Even if the breadcrumb function doesn't exist, your code here says to add that div. If you add this in header.php it will show you what template is being used on the page: <!-- <?php global $template; print_r($template); ?> --> – WebElaine Aug 22 '18 at 18:37
1

Posted the breadcrumbs in the wrong template page, moved to the correct page after suggestion from WebElaine to check which template was being used by placing:

<!-- <?php global $template; print_r($template); ?> -->

In the header.php file, which allowed me to view the template being used via source.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.