1. Go to this page and download the library: Download italystrap/breadcrumbs library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
italystrap / breadcrumbs example snippets
use ItalyStrap\Breadcrumbs;
echo Breadcrumbs_Factory::make( 'html', $args );
// Or
echo Breadcrumbs_Factory::make( 'json', $args );
/**
* 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,
];
/**
* 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' );
/**
* 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' );
/**
* 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' );
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.