feat: model projects as posts with a picked Selected work
Projects were hardcoded h3 elements in a pattern: no URL, no feed, no search, uneditable without touching PHP. They follow the podcast model now, a chrnx_topic term plus posts. Adds a chrnx_project_featured flag with an editor toggle so the stage lists chosen projects first and fills with the most recent. Sticky was already spoken for by the home featured stories, so the choice needed its own signal. journal-stream gains a pinned topic attribute, reusing the archive filter, pagination and empty state it already had. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
14 files changed
+539
-31
No files matched your search
+104
-7
@@ -95,9 +95,106 @@ function chrnx_get_card_media_markup( $post_id, $class_name ) {
|
||||
array( 'class' => $class_name . '__image' )
|
||||
);
|
||||
}
|
||||
|
||||
// A track with no art of its own borrows its album cover before falling back.
|
||||
$release = function_exists( 'chrnx_get_track_release' ) ? chrnx_get_track_release( $post_id ) : null;
|
||||
if ( null !== $release ) {
|
||||
$cover_id = absint( get_term_meta( $release->term_id, 'chrnx_release_cover', true ) );
|
||||
if ( $cover_id > 0 ) {
|
||||
return wp_get_attachment_image(
|
||||
$cover_id,
|
||||
'chrnx-card',
|
||||
false,
|
||||
array( 'class' => $class_name . '__image' )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$topic = chrnx_get_post_topic_slug( $post_id );
|
||||
$class = $class_name . '__fallback' . ( '' !== $topic ? ' is-topic-' . sanitize_html_class( $topic ) : '' );
|
||||
return '<span class="' . esc_attr( $class ) . '" aria-hidden="true"></span>';
|
||||
return chrnx_get_topic_portrait_markup( 'placeholder-post', '', $class );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the navigation links for one theme menu location.
|
||||
*
|
||||
* The built-in list is a fallback, not a contract: a site whose pages are named
|
||||
* differently would otherwise get a header full of 404s.
|
||||
*
|
||||
* @param string $location Registered menu location.
|
||||
* @return array<int,array<string,string>> Label and URL pairs.
|
||||
*/
|
||||
function chrnx_get_navigation_links( $location ) {
|
||||
$assigned = get_nav_menu_locations();
|
||||
$menu_id = isset( $assigned[ $location ] ) ? absint( $assigned[ $location ] ) : 0;
|
||||
if ( $menu_id > 0 ) {
|
||||
$items = wp_get_nav_menu_items( $menu_id );
|
||||
if ( is_array( $items ) ) {
|
||||
$links = array();
|
||||
foreach ( $items as $item ) {
|
||||
// Only top-level entries: the header is a single flat row.
|
||||
if ( absint( $item->menu_item_parent ) > 0 ) {
|
||||
continue;
|
||||
}
|
||||
$url = esc_url_raw( (string) $item->url );
|
||||
$label = trim( wp_strip_all_tags( (string) $item->title ) );
|
||||
if ( '' !== $url && '' !== $label ) {
|
||||
$links[] = array(
|
||||
'label' => $label,
|
||||
'url' => $url,
|
||||
);
|
||||
}
|
||||
}
|
||||
if ( ! empty( $links ) ) {
|
||||
return $links;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$defaults = array( 'journal', 'projects', 'music', 'podcasts', 'about' );
|
||||
$labels = array(
|
||||
'journal' => __( 'Journal', 'chrnx' ),
|
||||
'projects' => __( 'Projects', 'chrnx' ),
|
||||
'music' => __( 'Music', 'chrnx' ),
|
||||
'podcasts' => __( 'Podcasts', 'chrnx' ),
|
||||
'about' => __( 'About', 'chrnx' ),
|
||||
);
|
||||
$links = array();
|
||||
foreach ( $defaults as $slug ) {
|
||||
$links[] = array(
|
||||
'label' => $labels[ $slug ],
|
||||
'url' => home_url( '/' . $slug . '/' ),
|
||||
);
|
||||
}
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render one allowlisted interface icon.
|
||||
*
|
||||
* Unicode glyphs render inconsistently across platforms and fonts, so every
|
||||
* control icon comes from this one place instead.
|
||||
*
|
||||
* @param string $name Allowlisted icon name.
|
||||
* @param int $size Square pixel size.
|
||||
* @return string Escaped inline SVG, or an empty string for unknown names.
|
||||
*/
|
||||
function chrnx_get_icon_markup( $name, $size = 20 ) {
|
||||
$icons = array(
|
||||
'search' => '<circle cx="11" cy="11" r="7"/><path d="M20 20l-3.6-3.6"/>',
|
||||
'menu' => '<path d="M4 7h16M4 12h16M4 17h16"/>',
|
||||
'theme' => '<circle cx="12" cy="12" r="9"/><path d="M12 3a9 9 0 0 1 0 18Z" fill="currentColor" stroke="none"/>',
|
||||
);
|
||||
if ( ! isset( $icons[ $name ] ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
// The path data is a fixed literal, never user input.
|
||||
'<svg viewBox="0 0 24 24" width="%1$d" height="%1$d" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">%2$s</svg>',
|
||||
absint( $size ),
|
||||
$icons[ $name ] // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,16 +212,16 @@ function chrnx_get_editorial_card_markup( $post_id, $heading_level = 3, $class_n
|
||||
$post = get_post( $post_id );
|
||||
$heading_level = chrnx_get_heading_level( $heading_level, 3 );
|
||||
$topic_terms = get_the_terms( $post_id, 'chrnx_topic' );
|
||||
$topic_label = ! is_wp_error( $topic_terms ) && ! empty( $topic_terms ) ? $topic_terms[0]->name : '';
|
||||
$excerpt = wp_trim_words( wp_strip_all_tags( get_the_excerpt( $post ) ), 24 );
|
||||
// A card without a topic left an empty slot and knocked the row out of alignment.
|
||||
// Untopiced posts are still Journal entries, so that is the honest fallback.
|
||||
$topic_label = ! is_wp_error( $topic_terms ) && ! empty( $topic_terms ) ? $topic_terms[0]->name : __( 'Journal', 'chrnx' );
|
||||
$excerpt = wp_trim_words( wp_strip_all_tags( get_the_excerpt( $post ) ), 24 );
|
||||
|
||||
$markup = '<article class="' . esc_attr( $class_name ) . '">';
|
||||
$markup .= '<a class="' . esc_attr( $class_name . '__link' ) . '" href="' . esc_url( get_permalink( $post ) ) . '">';
|
||||
$markup .= chrnx_get_card_media_markup( $post_id, $class_name );
|
||||
$markup .= '<span class="' . esc_attr( $class_name . '__content' ) . '">';
|
||||
if ( '' !== $topic_label ) {
|
||||
$markup .= '<span class="' . esc_attr( $class_name . '__badge' ) . '">' . esc_html( $topic_label ) . '</span>';
|
||||
}
|
||||
$markup .= '<span class="' . esc_attr( $class_name . '__badge' ) . '">' . esc_html( $topic_label ) . '</span>';
|
||||
$markup .= '<h' . $heading_level . ' class="' . esc_attr( $class_name . '__title' ) . '">' . esc_html( get_the_title( $post ) ) . '</h' . $heading_level . '>';
|
||||
if ( '' !== $excerpt ) {
|
||||
$markup .= '<span class="' . esc_attr( $class_name . '__excerpt' ) . '">' . esc_html( $excerpt ) . '</span>';
|
||||
@@ -135,7 +232,7 @@ function chrnx_get_editorial_card_markup( $post_id, $heading_level = 3, $class_n
|
||||
|
||||
/** Register all block metadata directories that exist. */
|
||||
function chrnx_register_editorial_blocks() {
|
||||
$blocks = array( 'featured-stories', 'journal-stream', 'latest-podcast', 'podcast-meta', 'topic-hero', 'related-posts', 'subscribe-cta', 'theme-toggle', 'site-brand', 'mobile-menu-toggle', 'footer-content', 'header-tools', 'reading-time', 'journal-link' );
|
||||
$blocks = array( 'featured-stories', 'journal-stream', 'latest-podcast', 'podcast-meta', 'topic-hero', 'related-posts', 'subscribe-cta', 'theme-toggle', 'site-brand', 'mobile-menu-toggle', 'footer-content', 'header-tools', 'reading-time', 'journal-link', 'selected-work', 'release-list', 'release-detail', 'track-meta', 'subscribe-form' );
|
||||
foreach ( $blocks as $block ) {
|
||||
$name = 'chrnx/' . $block;
|
||||
if ( WP_Block_Type_Registry::get_instance()->is_registered( $name ) ) {
|
||||
|
||||
Reference in new issue
Block a user