`
haohappy2
  • 浏览: 319124 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

PHP BreadCrumb

阅读更多
<?php
/*
* Breadcrumb navigation class
* Mick Sear
* http://www.ecreate.co.uk
*
* The key to using this is to decide on a $level for each page.  (array, starting position 0)
* This determines where in the trail a link will be placed.  So, I normally make the homepage level 0,
* then every page that can be accessed from the top level nav becomes level 1, and every page
* from that second level becomes level 2, and so on.  When users return to a higher level (e.g. level 1)
* the surplus links are removed.  Only one page can occupy a $level in the crumb trail.
* There might be several routes to a page.  In which case, the trail will reflect the route that the
* user actually took to get to that page.
*/

class Breadcrumb{

   var $output;
   var $crumbs = array();
   var $location;


   /*
    * Constructor
    */
   function Breadcrumb(){  
   
      if ($_SESSION['breadcrumb'] != null){
         $this->crumbs = $_SESSION['breadcrumb'];
      }  
   
   }

   /*
    * Add a crumb to the trail:
    * @param $label - The string to display
    * @param $url - The url underlying the label
    * @param $level - The level of this link.  
    *
    */
   function add($label, $url, $level){

      $crumb = array();
      $crumb['label'] = $label;
      $crumb['url'] = $url;

      if ($crumb['label'] != null && $crumb['url'] != null && isset($level)){       
            
         while(count($this->crumbs) > $level){

            array_pop($this->crumbs); //prune until we reach the $level we've allocated to this page

         }

         if (!isset($this->crumbs[0]) && $level > 0){ //If there's no session data yet, assume a homepage link

            $this->crumbs[0]['url'] = "/index.php";
            $this->crumbs[0]['label'] = "Home";

         }

         $this->crumbs[$level] = $crumb;  
               
      }

        $_SESSION['breadcrumb'] = $this->crumbs; //Persist the data
        $this->crumbs[$level]['url'] = null; //Ditch the underlying url for the current page.
   }

   /*
    * Output a semantic list of links.  See above for sample CSS.  Modify this to suit your design.
    */
   function output(){

      echo "<div id='breadcrumb'><ul><li>Click trail: </li>";

      foreach ($this->crumbs as $crumb){  

         if ($crumb['url'] != null){

            echo "<li> > <a href='".$crumb['url']."' title='".$crumb['label']."'>".$crumb['label']."</a></li> ";

         } else {

            echo "<li> > ".$crumb['label']."</li> ";

         }
      }

      echo "</ul></div>";
   }
}
?> 

    Simple Usage

<?php
session_start();
include("./Breadcrumb.php");
$trail = new Breadcrumb();
$trail->add('Home', $_SERVER['PHP_SELF'], 0);

//Sample CSS
echo "
<style>
#breadcrumb ul li{
   list-style-image: none;
   display:inline;
   padding: 0 3px 0 0;
   margin: 3px 0 0 0;
}
#breadcrumb ul{
   margin:0;padding:0;
   list-style-type: none;
   padding-left: 1em;
}
</style>
";

//Now output the navigation.
$trail->output();
?>

 

0
0
分享到:
评论

相关推荐

    Laravel开发-breadcrumb

    在`config/app.php`文件的`providers`数组中添加`Spatie\Breadcrumb\BreadcrumbServiceProvider::class`。 接下来,配置面包屑。在`config/breadcrumb.php`(如果没有,需要创建)中,可以自定义面包屑的设置,如...

    breadcrumb-navxt.3.2.1

    - `breadcrumb-navxt.php`: 插件的主文件,包含了插件的核心功能和初始化代码。 - `css`或`stylesheets`目录:存放插件的样式表文件,用于定义面包屑导航的外观。 - `js`或`javascript`目录:存放插件的JavaScript...

    Laravel开发-breadcrumb-for-laravel

    5. **创建视图组件**:在`resources/views`目录下创建一个面包屑组件,如`breadcrumb.blade.php`,并使用提供的数据来渲染面包屑结构。 6. **在控制器中设置面包屑**:在处理请求的控制器方法中,使用`Breadcrumb::...

    Laravel开发-laravel-breadcrumb

    在Laravel框架中,"laravel-breadcrumb"通常是指一种用于构建网站导航面包屑的工具。面包屑导航是一种用户界面元素,它可以帮助用户理解他们在网站结构中的位置,并能方便地返回上一级或首页。在本篇文章中,我们将...

    Codeigniter-breadcrumbs, 用于CodeIgniter的小breadcrumb库.zip

    Codeigniter-breadcrumbs, 用于CodeIgniter的小breadcrumb库 Breadcrumbs是一个小型库,它帮助你使用CodeIgniter管理HTML面包屑。 * 不再维护 Instalation将 Breadcrumbs.php 放在应用程序/库文件夹中将 Breadcrumbs...

    breadcrumb tag

    标题中的“breadcrumb tag”通常指的是面包屑导航标签,它是一种用户界面设计元素,常用于网站和应用程序中,帮助用户理解他们当前在网站结构中的位置,并能方便地返回上级或起始页面。面包屑导航来源于格林童话...

    Breadcrumb-for-Codeigniter:Breadcrumb用于Codeigniter的插件

    复制config文件夹中的breadcrumb.php文件,并粘贴到项目中的application/config文件夹中 将“ libraries”文件夹中的“ Breadcrumb.php文件复制并粘贴到项目的application/libraries文件夹中 通过将以下代码段添加...

    laravel-route-breadcrumb:Laravel

    如果您还希望使用facade访问主面包屑类,请将此行添加到config / app.php中的facades数组中: 'Breadcrumb' =&gt; Fragkp \ LaravelRouteBreadcrumb \ Facades \ Breadcrumb ::class, 该软件包包含一些最活跃的css-...

    Breadcrumb-NavXT:WordPress维护时间最长的Breadcrumb插件

    Breadcrumb-NavXT是一款针对WordPress平台的插件,其主要功能是为网站添加面包屑导航(Breadcrumb Navigation)。面包屑导航是一种用户界面元素,它帮助用户理解当前所在的位置,并能方便地返回到之前的页面或网站的...

    Fuel-Breadcrumb:面包屑自动生成器类到 FuelPHP

    'Breadcrumb' =&gt; APPPATH.'classes/breadcrumb.php', )); 用法 $this-&gt;template-&gt;set_global('breadcrumb', \Breadcrumb::create_links(), false); 执照 这是在 MIT 许可下发布的。 文档 文档即将推出... 随意...

    php影视管理系统,seacms,feifei,面包,影视网站学习开源源码,免费版,可以使用

    “面包”在这里可能指的是“面包屑导航”(Breadcrumb Navigation),这是一种用户界面元素,显示用户在网站中的位置,有助于用户理解和导航复杂的网站结构。在影视网站中,面包屑导航可能显示为“首页 &gt; 影视分类 &gt;...

    centrodametropole_breadcrumb:大都会中心的Drupal模块

    作为PHP编程语言的实现,`centrodametropole_breadcrumb`模块利用Drupal的钩子系统(Hooks)和主题系统来定制面包屑行为。PHP是Drupal的核心语言,开发者可以编写PHP代码来扩展和定制Drupal的功能。在这个模块中,...

    Laravel-4-breadcrumb:用于 Laravel 4 的小型且易于定制的面包屑生成器

    设置在您的配置文件夹中打开 app.php 将'Mj\Breadcrumb\BreadcrumbServiceProvider'行添加到提供者数组中。 要使用 Laravel 4 附带的 Facade,请确保在文件“app/config/app.php”中注册别名。 像这样: 'Breadcrumb...

    WooCommerce-Breadcrumb-Permalinks:允许具有父类别和子类别的WooCommerce单一产品页面的面包屑固定链接

    总之,"WooCommerce Breadcrumb Permalinks"插件是一个实用的工具,它提升了多层级分类产品的用户体验,同时也展示了在WordPress和WooCommerce环境中进行PHP编程和插件开发的可能性。对于想要深入学习WooCommerce...

    wb_breadcrumb:基于沙箱https的menu_breadcrumb端口到D8#2149577

    利润 )) 在主题中,您可以覆盖添加的“ wb_breadcrumb.html.twig”模板并从模块中复制。 去下载git clone --branch 8.x-1.x http://git.drupal.org/sandbox/oles89/2367919.git cd wb_breadcrumbs 维护者

    网站导航_所在位置代码

    创建面包屑导航的HTML结构,例如:`&lt;nav class="breadcrumb"&gt;...&lt;/nav&gt;`,并用PHP动态填充每个层级的链接。 5. **PHP循环**:遍历路径数组,为每个层级生成对应的链接。可以使用`foreach`循环,通过检查当前层级与...

    Laravel开发-breadcrumbs

    &lt;li class="breadcrumb-item{{ $breadcrumb-&gt;active ? ' active' : '' }}"&gt; @if (!$breadcrumb-&gt;active) $breadcrumb-&gt;url }}"&gt;{{ $breadcrumb-&gt;title }} @else {{ $breadcrumb-&gt;title }} @endif @endfor...

Global site tag (gtag.js) - Google Analytics