Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/vendor
.vscode
88 changes: 52 additions & 36 deletions src/Crumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,50 +199,66 @@ public function build()
);
}

if (is_singular('post')) {
$categories = get_the_category(get_the_ID());
if (is_singular()) {
$postType = get_post_type();
$postTypeObject = get_post_type_object($postType);

// Add post type archive link if it exists
if ($postTypeObject && !empty($postTypeObject->has_archive)) {
$this->add(
$postTypeObject->label,
get_post_type_archive_link($postType)
);
}

if (! empty($categories)) {
foreach ($categories as $index => $category) {
$this->add(
$category->name,
get_category_link($category),
$category->term_id,
$index === 0
);
// Add custom taxonomy terms
$taxonomies = get_object_taxonomies($postType, 'objects');
foreach ($taxonomies as $taxonomy) {
if ($taxonomy->public) {
$terms = get_the_terms(get_the_ID(), $taxonomy->name);
if (!empty($terms) && !is_wp_error($terms)) {
if ($taxonomy->hierarchical) {
// Handle hierarchical taxonomies
$term = array_shift($terms); // Get the first term
$ancestors = get_ancestors($term->term_id, $taxonomy->name);

// Add ancestor terms
foreach (array_reverse($ancestors) as $ancestorId) {
$ancestor = get_term($ancestorId, $taxonomy->name);
$this->add(
$ancestor->name,
get_term_link($ancestor, $taxonomy->name),
$ancestor->term_id
);
}

// Add the current term
$this->add(
$term->name,
get_term_link($term, $taxonomy->name),
$term->term_id
);
} else {
// Handle non-hierarchical taxonomies
foreach ($terms as $term) {
$this->add(
$term->name,
get_term_link($term, $taxonomy->name),
$term->term_id
);
}
}
}
}

return $this->add(
get_the_title(),
null,
get_the_ID()
);
}

// Add the current post
return $this->add(
get_the_title(),
null,
get_the_ID(),
true
);
}

$type = get_post_type_object(
get_post_type()
);

if (! empty($type)) {
$this->add(
$type->label,
get_post_type_archive_link($type->name),
get_queried_object_id()
get_the_ID()
);
}

return $this->add(
get_the_title(),
null,
get_the_ID()
);
return $this->breadcrumb;
}
}