✨feature: Implement project-type taxonomy archive template and enhance breadcrumb navigation
Sync TODOs with Issues / sync_todos (push) Successful in 8s
Sync TODOs with Issues / sync_todos (push) Successful in 8s
This commit is contained in:
@@ -46,7 +46,11 @@ class Breadcrumbs {
|
||||
// Static Page - add the parent pages if any, and the page title
|
||||
$breadcrumbs = array_merge( $breadcrumbs, self::getStaticPageBreadcrumbs( $post ) );
|
||||
} elseif ( is_category() || is_tag() || is_tax() ) {
|
||||
// Taxonomy Archive - add the taxonomy term name
|
||||
// Taxonomy Archive - if this is a project-type term, surface the
|
||||
// Projects archive as a clickable parent in the trail.
|
||||
if ( is_tax( 'project-type' ) ) {
|
||||
$breadcrumbs[] = self::getProjectsArchiveLinkBreadcrumb();
|
||||
}
|
||||
$breadcrumbs[] = self::getTaxonomyArchiveBreadcrumb();
|
||||
} elseif ( is_post_type_archive() ) {
|
||||
// Post Type Archive - add the post type name
|
||||
@@ -205,6 +209,24 @@ class Breadcrumbs {
|
||||
return $postType ? array( 'label' => $postType->labels->name ) : array();
|
||||
}
|
||||
|
||||
/** Generates a clickable Projects archive breadcrumb.
|
||||
*
|
||||
* Used in the taxonomy archive trail so users have a working "back to
|
||||
* all projects" link in the breadcrumb. Distinct from
|
||||
* getPostTypeArchiveBreadcrumb(), which omits the URL because on the
|
||||
* post-type archive itself that crumb is the active leaf and shouldn't
|
||||
* link to itself.
|
||||
*
|
||||
* @return array Breadcrumb data with both label and url.
|
||||
*/
|
||||
private static function getProjectsArchiveLinkBreadcrumb() {
|
||||
$url = get_post_type_archive_link( 'projects' );
|
||||
return array(
|
||||
'url' => $url ? $url : '',
|
||||
'label' => __( 'Projects', 'ks-portfolio' ),
|
||||
);
|
||||
}
|
||||
|
||||
/** Generates breadcrumbs for date-based archives.
|
||||
*
|
||||
* This method is responsible for creating breadcrumb navigation
|
||||
|
||||
@@ -154,6 +154,8 @@ function getTheTitle() {
|
||||
if ( is_home() || is_single() ) {
|
||||
$title = get_the_title( get_option( 'page_for_posts', true ) );
|
||||
} elseif ( is_archive() ) {
|
||||
// get_the_archive_title() is filtered below to drop the
|
||||
// "Project Type:" / "Category:" prefix — see stripArchiveTitlePrefix().
|
||||
$title = get_the_archive_title();
|
||||
} elseif ( is_search() ) {
|
||||
$title = sprintf(
|
||||
@@ -170,6 +172,26 @@ function getTheTitle() {
|
||||
return $title;
|
||||
}
|
||||
|
||||
/** Strip the "Project Type:" / "Category:" / "Tag:" prefix from archive titles.
|
||||
*
|
||||
* WordPress's get_the_archive_title() returns plain text with the taxonomy
|
||||
* or post-type label concatenated before a colon (e.g. "Project Type: Plugins",
|
||||
* "Category: WordPress", "Tag: php"). The site's hero partial uses the raw
|
||||
* archive title as its <h1>, and templates render their own context-appropriate
|
||||
* headers, so the prefix is redundant and visually noisy.
|
||||
*
|
||||
* @param string $title The full archive title, including prefix.
|
||||
* @return string The title with the prefix removed.
|
||||
*/
|
||||
function stripArchiveTitlePrefix( $title ) {
|
||||
// Drop the "<Label>: " prefix WordPress prepends. The label may be wrapped
|
||||
// in a <span> on some archive types (date archives) — strip that too.
|
||||
$title = (string) $title;
|
||||
$title = preg_replace( '/^\s*(?:<[^>]+>\s*)*[^:<]+:\s*/u', '', $title );
|
||||
return $title;
|
||||
}
|
||||
add_filter( 'get_the_archive_title', __NAMESPACE__ . '\\stripArchiveTitlePrefix' );
|
||||
|
||||
/** Wraps iframes and embed elements in a div with a specific class.
|
||||
*
|
||||
* This function searches for iframe and embed elements within the provided
|
||||
@@ -198,6 +220,26 @@ function divWrapper( $content ) {
|
||||
|
||||
add_filter( 'the_content', __NAMESPACE__ . '\\divWrapper' );
|
||||
|
||||
/** Strip the "<Label>: " prefix from the document title.
|
||||
*
|
||||
* The SEO Framework wipes out all `pre_get_document_title` filters at
|
||||
* `template_redirect` priority 20 and composes the title itself. To strip
|
||||
* the archive prefix consistently across <title>, og:title, and twitter:title
|
||||
* (which all derive from TSF's generated archive title list), hook the
|
||||
* archive-title-items filter and return the unprefixed title.
|
||||
*
|
||||
* @param array $items [title, prefix, title_without_prefix]
|
||||
* @return array The same items with the prefix removed from the title.
|
||||
*/
|
||||
function stripArchiveTitleItemsPrefix( $items ) {
|
||||
if ( ! is_array( $items ) || empty( $items[2] ) ) {
|
||||
return $items;
|
||||
}
|
||||
$items[0] = $items[2];
|
||||
return $items;
|
||||
}
|
||||
add_filter( 'the_seo_framework_generated_archive_title_items', __NAMESPACE__ . '\\stripArchiveTitleItemsPrefix' );
|
||||
|
||||
/** Selectively add sidebar to page.
|
||||
*
|
||||
* This function adds a custom field group to the WordPress editor for
|
||||
|
||||
Reference in New Issue
Block a user