0

I have the following code of breadcrumbs (in functions.php). It works fine, but it has too many if statements. Maybe more logical reconfig to switch/case? How can I do it?

function the_breadcrumb()
{
    if (!is_front_page())
    {
        echo '<li><a href="' . get_option( 'home' ) . '"> Home </a><li>';

        if (is_category() || is_single()) the_category(' ');
        if (is_page()) the_title();
        if (is_archive()) echo "<span class='slicer'></span>";
        if (is_single()) echo "<span class='slicer'></span>";
        if (!is_category() && is_single()) the_title();
    }
    else {
        echo 'Home';
    }
}
Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
WebArtisan
  • 3,996
  • 10
  • 42
  • 62
  • 1
    Your code is a lot simpler than other people's code: http://stackoverflow.com/questions/2594211/php-simple-dynamic-breadcrumb – dcaswell Sep 07 '13 at 06:56
  • 2
    I don't think it needs any refactoring since you couldn't just use a switch, you'd still need some extra if conditionals, specifically because `is_single()` produces two outputs and because there's no logical AND in a switch – omma2289 Sep 07 '13 at 07:08

1 Answers1

0

so.. i`m updateted my func but i stil thinking - this is not universaly.

function do_the_breadcrumb() {
echo '<ol class="breadcrumb">';
if (!is_home()) {
    echo '<li><a href="'.get_option('home').'"> Home </a></li>';
    if (is_category() || is_single()) {
        echo '<li>';
        the_category(' </li><li> ');
        if (is_single()) {
            echo "</li><li class='active'>";
            the_title();
            echo '</li>';
        }
    } elseif (is_page()) {
        echo '<li class="active">';
        echo the_title();
        echo '</li>';
    }
    elseif (is_tag()) { echo the_tags("<li class='active'>Following tags: &nbsp; </li>","&nbsp;<span class='slicer'></span>");}
    elseif (is_archive()) { echo "<li class='active'>Archive Page</li>"; }
    elseif (is_author()) { echo "<li class='active'>Author Archive</li>";}
    elseif (is_search()) { echo "<li class='active'>Search Page</li>";}
}
elseif (isset($_GET['paged']) && !empty($_GET['paged']))
{
    echo '<li><a href="'.get_option('home').'"> Home </a></li>'."<li class='active'>Blog Pages</li>";
}
else {
    echo"<li class='active'> Home </li>";
}
echo "</ol>";

}

WebArtisan
  • 3,996
  • 10
  • 42
  • 62