Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix breadcrumbs. #166

Merged
merged 10 commits into from
Jan 19, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix breadcrumbs.
StevenDufresne committed Jan 19, 2023
commit 3015814146de769b1053d2121544e562a77f98e6
25 changes: 25 additions & 0 deletions source/wp-content/themes/wporg-developer-2023/functions.php
Original file line number Diff line number Diff line change
@@ -137,6 +137,7 @@
require __DIR__ . '/inc/block-hooks.php';

// Block files
require_once __DIR__ . '/src/breadcrumbs/index.php';
require_once __DIR__ . '/src/code-changelog/block.php';
require_once __DIR__ . '/src/code-deprecated/block.php';
require_once __DIR__ . '/src/code-description/block.php';
@@ -177,6 +178,7 @@ function init() {

// Modify default breadcrumbs.
add_filter( 'breadcrumb_trail_items', __NAMESPACE__ . '\\breadcrumb_trail_items_for_hooks', 10, 2 );
add_filter( 'breadcrumb_trail_items', __NAMESPACE__ . '\\breadcrumb_trail_items_remove_reference', 11, 2 );
add_filter( 'breadcrumb_trail_items', __NAMESPACE__ . '\\breadcrumb_trail_items_for_handbook_root', 10, 2 );

add_filter( 'mkaz_code_syntax_force_loading', '__return_true' );
@@ -214,6 +216,29 @@ function breadcrumb_trail_items_for_hooks( $items, $args ) {
return $items;
}

/**
* Remove the 'Reference' part of the breadcrumb trail.
*
* @param array $items The breadcrumb trail items.
* @param array $args Original args.
* @return array
*/
function breadcrumb_trail_items_remove_reference( $items, $args ) {
if ( ! is_singular() && ! is_single() && ! is_post_type_archive() ) {
return $items;
}

return array_filter(
$items,
function( $item ) {
// Remove the 'reference' parent based on the presence of its URL.
// We can't use the label because of internationalization.
$result = (bool) preg_match( '/href=".*\/reference\/"/', $item, $matches );
StevenDufresne marked this conversation as resolved.
Show resolved Hide resolved
return ( false === $result );
}
);
}

/**
* Fix breadcrumb for handbook root pages.
*
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ function breadcrumb_trail( $args = array() ) {
else
$breadcrumb = new Breadcrumb_Trail( $args );

$breadcrumb->trail();
return $breadcrumb->trail();
}

/**
@@ -89,8 +89,8 @@ public function __construct( $args = array() ) {
'network' => false,
//'show_edit_link' => false,
'show_title' => true,
'show_browse' => true,
'echo' => true,
'show_browse' => false,
'echo' => false,

/* Post taxonomy (examples follow). */
'post_taxonomy' => array(
@@ -187,8 +187,8 @@ public function default_labels() {

$labels = array(
'browse' => __( 'Browse:', 'breadcrumb-trail' ),
'home' => __( 'Home', 'breadcrumb-trail' ),
'search' => __( 'Search results for "%s"', 'breadcrumb-trail' ),
'home' => __( 'Developer', 'breadcrumb-trail' ),
'search' => __( 'Result', 'breadcrumb-trail' ),
'error_404' => __( '404 Not Found', 'breadcrumb-trail' ),
'paged' => __( 'Page %d', 'breadcrumb-trail' ),
'archives' => __( 'Archives', 'breadcrumb-trail' ),
Original file line number Diff line number Diff line change
@@ -2,8 +2,8 @@

<!-- wp:group {"align":"full","style":{"spacing":{"padding":{"top":"16px","right":"var:preset|spacing|edge-space","bottom":"16px","left":"var:preset|spacing|edge-space"}},"elements":{"link":{"color":{"text":"var:preset|color|white"}}}},"backgroundColor":"blueberry-1","textColor":"white","className":"is-sticky","layout":{"type":"constrained"}} -->
<div class="wp-block-group alignfull is-sticky has-white-color has-blueberry-1-background-color has-text-color has-background has-link-color" style="padding-top:16px;padding-right:var(--wp--preset--spacing--edge-space);padding-bottom:16px;padding-left:var(--wp--preset--spacing--edge-space)"><!-- wp:group {"align":"full","layout":{"type":"flex","flexWrap":"wrap","justifyContent":"space-between"}} -->
<div class="wp-block-group alignfull"><!-- wp:group {"layout":{"type":"flex","flexWrap":"nowrap"},"className":"wporg-site-breadcrumbs-container"} -->
<div class="wp-block-group wporg-site-breadcrumbs-container"><!-- wp:wporg/site-breadcrumbs {"fontSize":"small"} /--></div>
<div class="wp-block-group alignfull"><!-- wp:group {"layout":{"type":"flex","flexWrap":"nowrap"}} -->
<div class="wp-block-group"><!-- wp:wporg/breadcrumbs /--></div>
<!-- /wp:group -->

<!-- wp:navigation {"textColor":"white","backgroundColor":"blueberry-1","className":"is-style-dropdown-on-mobile","style":{"spacing":{"blockGap":"24px"}},"fontSize":"small"} -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"name": "wporg/breadcrumbs",
"title": "Breadcrumbs",
"category": "layout",
"description": "Shows breadcrumbs.",
"keywords": [ "post" ],
"textdomain": "wporg",
"attributes": {},
"supports": {
"html": false,
"color": {
"text": true,
"background": true,
"link": true
},
"spacing": {
"margin": true,
"padding": true
},
"typography": {
"fontSize": true,
"lineHeight": true
}
},
"usesContext": [ "postId" ],
"editorScript": "file:./index.js",
"style": "file:./style-index.css"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* WordPress dependencies
*/
import { registerBlockType } from '@wordpress/blocks';
import { useBlockProps } from '@wordpress/block-editor';

/**
* Internal dependencies
*/
import metadata from './block.json';
import './style.scss';

function Edit() {
return <div { ...useBlockProps() }>Search Title</div>;
}

registerBlockType( metadata.name, {
edit: Edit,
save: () => null,
} );
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Block Name: Breadcrumbs
* Description: A dynamic generated breadcrumb.
*
* @package wporg
*/

namespace WordPressdotorg\Theme\Developer_2023\Dynamic_Breadcrumbs;

add_action( 'init', __NAMESPACE__ . '\init' );

/**
* Registers the block using the metadata loaded from the `block.json` file.
* Behind the scenes, it registers also all assets so they can be enqueued
* through the block editor in the corresponding context.
*
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function init() {
register_block_type(
dirname( dirname( __DIR__ ) ) . '/build/breadcrumbs',
array(
'render_callback' => __NAMESPACE__ . '\render',
)
);
}

/**
* Render the block content.
*
* @param array $attributes Block attributes.
* @param string $content Block default content.
* @param WP_Block $block Block instance.
*
* @return string Returns the block markup.
*/
function render( $attributes, $content, $block ) {
$wrapper_attributes = get_block_wrapper_attributes();
return sprintf(
'<div %1$s>%2$s</div>',
$wrapper_attributes,
breadcrumb_trail(),
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.trail-end {
font-weight: 700;
}