2013-01-13 26 views
2

我一直在想弄清楚如何让我的面包屑中的最后一项有H1标签。这是一个没有H1的示例代码。Simple Breadcrumb问题

// Each tree item has a URL and name. Some may have extra_before and extra_after. 
foreach ($context['lateral_navigation'] as $link_num => $tree) 
{ 
    echo ' 
     <li', ($link_num == count($context['lateral_navigation']) - 1) ? ' class="last"' : '', '>'; 

    // Show something before the link? 
    if (isset($tree['extra_before'])) 
     echo $tree['extra_before']; 

    // Show the link, including a URL if it should have one. 
    echo $settings['lateral_navigation_link'] && isset($tree['url']) ? ' 
      <a href="' . $tree['url'] . '">' . $tree['name'] . ' 
      </a>' : '' . $tree['name'] . ''; 

    // Show something after the link...? 
    if (isset($tree['extra_after'])) 
     echo $tree['extra_after']; 

    echo ' 
     </li>'; 

我不是PHPer,我已经试过这条线上尝试用它的代码:

<li', ($link_num == count($context['lateral_navigation']) - 1) ? ' class="last"' : '', '>'; 

因为它显示了“最后”仅在面包屑的最后一个项目。

我厌倦了这样的下面,但显然没有奏效:

// Each tree item has a URL and name. Some may have extra_before and extra_after. 
foreach ($context['lateral_navigation'] as $link_num => $tree) 
{ 
    echo ' 
     <li', ($link_num == count($context['lateral_navigation']) - 1) ? ' class="last"><h1>' : '', '>'; 

    // Show something before the link? 
    if (isset($tree['extra_before'])) 
     echo $tree['extra_before']; 

    // Show the link, including a URL if it should have one. 
    echo $settings['lateral_navigation_link'] && isset($tree['url']) ? ' 
      <a href="' . $tree['url'] . '">' . $tree['name'] . ' 
       <div id="arrow"> 
        <div class="inside"></div> 
        <div class="border"></div> 
       </div> 
      </a>' : '' . $tree['name'] . ''; 

    // Show something after the link...? 
    if (isset($tree['extra_after'])) 
     echo $tree['extra_after']; 

    // Don't show a separator for the last one. 
    if ($link_num != count($context['lateral_navigation']) - 1) 
     echo ''; 

    echo ' 
     </h1', ($link_num == count($context['lateral_navigation']) - 1) , '></li>'; 
} 

任何帮助?

回答

4

试试这个:

$count = count($context['lateral_navigation']); // get count 

// Each tree item has a URL and name. Some may have extra_before and extra_after. 
foreach ($context['lateral_navigation'] as $link_num => $tree) 
{ 
    $count--; // decrement by 1 
    echo ($count == 0) // if zero (last) 
     ? '<li class="last"><h1>' 
     : '<li>'; 

    // Show something before the link? 
    if (isset($tree['extra_before'])) 
     echo $tree['extra_before']; 

    // Show the link, including a URL if it should have one. 
    echo $settings['lateral_navigation_link'] && isset($tree['url']) ? ' 
      <a href="' . $tree['url'] . '">' . $tree['name'] . ' 
       <div id="arrow"> 
        <div class="inside"></div> 
        <div class="border"></div> 
       </div> 
      </a>' : '' . $tree['name'] . ''; 

    // Show something after the link...? 
    if (isset($tree['extra_after'])) 
     echo $tree['extra_after']; 

    // Don't show a separator for the last one. 
    if ($link_num != count($context['lateral_navigation']) - 1) 
     echo ''; 

    echo ($count == 0) // if zero (last) 
     ? '</h1></li>' 
     : '</li>'; 
} 
+0

对不起,我最初忘了默认的'LI'标签。但现在会回应他们。 –

+0

工程就像一个魅力,谢谢。 – Xarcell