italystrap/breadcrumbs
Composer 安装命令:
composer require italystrap/breadcrumbs
包简介
ItalyStrap Breadcrumbs Class
关键字:
README 文档
README
Breadcrumbs Class API for WordPress
This package create an HTML or Json Breadcrumbs elements to display on your WordPress site
Installation
Install with Composer
Add the package to your projects composer.json file. Visit getcomposer.org more information.
composer require italystrap/breadcrumbs
or
{
"require": {
"italystrap/breadcrumbs": "dev-master"
}
}
Install Manually
Download and include the class file into your theme/plugin:
include_once 'path/to/ItalyStrap/Breadcrumbs.php';
Usage
Basic usage
Use \ItalyStrap\Breadcrumbs\Breadcrumbs_Factory::make( $type, $args ) to display the breadcrumbs in your template.
use ItalyStrap\Breadcrumbs; echo Breadcrumbs_Factory::make( 'html', $args ); // Or echo Breadcrumbs_Factory::make( 'json', $args );
The first parameter is the type of breadcrumbs you want to display:
- HTML
- Return the HTML output
- Json
- Return the Json output
- object
- Return the object output
- array
- Return the array output
Options
An optional array of arguments can be passed to modify the breadcrumb output.
The defaults for each option @see Breadcrumbs/config/breadcrumbs.php
/** * Default configuration for Breadcrumbs */ return [ /** * This is the container of the breadcrumbs * @example <nav aria-label="breadcrumb">...</nav> */ 'container_tag' => 'nav', 'container_attr' => [ 'aria-label' => 'breadcrumb', ], /** * This is the list tag of the breadcrumbs * @example <ol class="breadcrumb" itemscope itemtype="https://schema.org/BreadcrumbList">...</ol> */ 'list_tag' => 'ol', 'list_attr' => [ 'class' => 'breadcrumb', 'itemscope' => true, 'itemtype' => 'https://schema.org/BreadcrumbList', ], /** * This is the item tag of the breadcrumbs * @example <li class="breadcrumb-item [...active]" itemprop="itemListElement" itemscope itemtype="https://schema.org/ListItem">...</li> */ 'item_tag' => 'li', 'item_attr' => [ 'class' => "breadcrumb-item", 'itemprop' => 'itemListElement', 'itemscope' => true, 'itemtype' => 'https://schema.org/ListItem', ], /** * Css class for active element */ 'item_attr_class_active' => ' active', /** * It could be passed an HTML icon to show instead of the firt element (home) * @example <span class="glyphicon glyphicon-home" aria-hidden="true"></span> */ 'home_icon' => false, /** * Separator for the items * @example ' /' */ 'separator' => false, /** * Show on front * @default true */ 'show_on_front' => true, ];
Default HTML output
<nav aria-label="breadcrumb"> <ol class="breadcrumb" itemscope="" itemtype="https://schema.org/BreadcrumbList"> <meta name="numberOfItems" content="2"> <meta name="itemListOrder" content="Ascending"> <li class="breadcrumb-item" itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem"> <a itemprop="item" href="http://192.168.1.10/italystrap/"> <span itemprop="name">ItalyStrap</span></a> <meta itemprop="position" content="1"> </li> <li class="breadcrumb-item active" itemprop="itemListElement" itemscope="" itemtype="https://schema.org/ListItem" aria-current="page"> <a itemprop="item" href="http://192.168.1.10/italystrap/blog/"> <span itemprop="name">Blog</span></a> <meta itemprop="position" content="2"> </li> </ol> </nav>
Advanced usage
Example for HTML version
YOu can copy this snippet in your file breadcrumbs.php and include it in your plugin/theme
/** * Get the Breadcrumbs * * @param array $args The breadcrumbs arguments. * @see class Breadcrumbs for more info. * @return string Return the breadcrumbs html. */ function get_breadcrumbs( array $args = array() ) { $args['bloginfo_name'] = GET_BLOGINFO_NAME; $args['home_url'] = HOME_URL; $args['separator'] = false; $args['show_on_front'] = false; try { return apply_filters( 'italystrap_get_the_breadcrumbs', \ItalyStrap\Breadcrumbs\Breadcrumbs_Factory::make( 'html', $args ), $args ); } catch ( Exception $e ) { echo $e->getMessage(); } } /** * Print the Breadcrumbs * * @param array $args The breadcrumbs arguments. * @see class Breadcrumbs for more info. * @return string Return the breadcrumbs html. */ function breadcrumbs( array $args = array() ) { echo get_breadcrumbs( $args ); } /** * Do breadcrumbs * * @since 2.2.0 * * @param array $args The breadcrumbs arguments. */ function do_breadcrumbs( array $args = array() ) { breadcrumbs( $args ); } add_action( 'do_breadcrumbs', __NAMESPACE__ . '\do_breadcrumbs' );
Then with the function do_action( 'do_breadcrumbs', [] ) you can display the breadcrumbs where you want in your theme.
Example for Json version
/** * Get the Breadcrumbs * * @param array $args The breadcrumbs arguments. * @see class Breadcrumbs for more info. * @return string Return the breadcrumbs html. */ function get_breadcrumbs( array $args = array() ) { $args['bloginfo_name'] = GET_BLOGINFO_NAME; $args['home_url'] = HOME_URL; $args['show_on_front'] = false; try { return apply_filters( 'italystrap_get_the_breadcrumbs', \ItalyStrap\Breadcrumbs\Breadcrumbs_Factory::make( 'json', $args ), $args ); } catch ( Exception $e ) { echo $e->getMessage(); } } /** * Print the Breadcrumbs * * @param array $args The breadcrumbs arguments. * @see class Breadcrumbs for more info. * @return string Return the breadcrumbs html. */ function breadcrumbs( array $args = array() ) { echo get_breadcrumbs( $args ); } /** * Do breadcrumbs * * @since 2.2.0 * * @param array $args The breadcrumbs arguments. */ function do_breadcrumbs( array $args = array() ) { breadcrumbs( $args ); } add_action( 'wp_footer', __NAMESPACE__ . '\do_breadcrumbs' );
Filters
TODO
Other Example
TODO
array_insert()
array_insert() is a function that allows you to insert a new element into an array at a specific index.
Example array_insert()
/** * Modify breadcrums list * * @param {array} $list * * @return {array} */ function modify_breadcrumbs_list( array $list ) { // if on the events category archive page if( is_tax( 'event-categories' ) ) { // create a new element $element = [ 'title' => "Shows", 'url' => site_url( '/shows' ) ]; // add the new element at the index of 1 $list = array_insert( $list, $element, 1 ); } return $list; } add_filter( 'ItalyStrap\Breadcrumbs\Container\Items', 'modify_breadcrumbs_list' );
Notes
- Licensed under the GNU General Public License v2.0
- Maintained under the Semantic Versioning Guide
Author
Enea Overclokk
italystrap/breadcrumbs 适用场景与选型建议
italystrap/breadcrumbs 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 279 次下载、GitHub Stars 达 2, 最近一次更新时间为 2018 年 11 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「wordpress」 「breadcrumbs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 italystrap/breadcrumbs 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 italystrap/breadcrumbs 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 italystrap/breadcrumbs 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Breadcrumbs integration for Laravel 6
Navigation bundle for Symfony applications
Control pro Nette Framework usnadňující tvorbu menu a drobečkové navigace
Easy breadcrumbs navigation for Pimple powered apps, tested with Silex.
Breadcrumbs
Simple breadcrumbs service for Laravel.
统计信息
- 总下载量: 279
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-11-22