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

json_encode returns empty object #6

Open
ghost opened this issue Jun 2, 2020 · 3 comments
Open

json_encode returns empty object #6

ghost opened this issue Jun 2, 2020 · 3 comments

Comments

@ghost
Copy link

ghost commented Jun 2, 2020

Hey @justintadlock

Thanks for your great work! However, I am encountering an issue when trying to print the array/objects to the front-end.

Following code is returning an empty array/object:

use Hybrid\Breadcrumbs\Trail;

$tax = [
	'post' => 'category'
];

$labels = [
	'title'               => __( 'Browse:', 'hybrid-core' ),
	'aria_label'          => _x( 'Breadcrumbs', 'breadcrumbs aria label', 'hybrid-core' ),
	'home'                => __( 'Home', 'hybrid-core' ),
	'error_404'           => __( '404 Not Found', 'hybrid-core' ),
	'archives'            => __( 'Archives', 'hybrid-core' ),
	'search'              => __( 'Search results for: %s', 'hybrid-core' ),
	'paged'               => __( 'Page %s', 'hybrid-core' ),
	'paged_comments'      => __( 'Comment Page %s', 'hybrid-core' ),
	'archive_minute'      => __( 'Minute %s', 'hybrid-core' ),
	'archive_week'        => __( 'Week %s', 'hybrid-core' ),
	'archive_minute_hour' => '%s',
	'archive_hour'        => '%s',
	'archive_day'         => '%s',
	'archive_month'       => '%s',
	'archive_year'        => '%s',
];

$defaults = [
	'labels'          => $labels,
	'post_taxonomy'   => $tax,
	'show_on_front'   => true,
	'show_trail_end'  => true,
	'network'         => true,
	'before'          => 'test',
	'after'           => 'test',
	'container_tag'   => 'nav',
	'title_tag'       => 'h2',
	'list_tag'        => 'ul',
	'item_tag'        => 'li',
	'container_class' => 'breadcrumbs',
	'title_class'     => 'breadcrumbs__title',
	'list_class'      => 'breadcrumbs__trail',
	'item_class'      => 'breadcrumbs__crumb'
];

echo json_encode( Trail::make( $defaults ) );
echo json_encode( Trail::all( $defaults ) );

Am I missing something here? Trail::render works without problems.

Thanks!
Dennis

@ernilambar
Copy link

@dnnsjsk Did you try Trail::display();?

@ghost
Copy link
Author

ghost commented Jun 5, 2020

@ernilambar That works as well, but I need the breadcrumb data as an Array/Object and not rendered already.

@ernilambar
Copy link

@dnnsjsk Hybrid\Breadcrumbs\Trail::all() gives all breadcrumb items.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant