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 ) ) {
|
||||
|
||||
@@ -45,7 +45,25 @@ function chrnx_enqueue_editor_assets() {
|
||||
true
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'chrnx-editor-project',
|
||||
get_theme_file_uri( 'assets/js/editor-project.js' ),
|
||||
array( 'wp-components', 'wp-core-data', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins' ),
|
||||
CHRNX_VERSION,
|
||||
true
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'chrnx-editor-track',
|
||||
get_theme_file_uri( 'assets/js/editor-track.js' ),
|
||||
array( 'wp-block-editor', 'wp-components', 'wp-core-data', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins' ),
|
||||
CHRNX_VERSION,
|
||||
true
|
||||
);
|
||||
|
||||
wp_set_script_translations( 'chrnx-editor-taxonomies', 'chrnx', get_theme_file_path( 'languages' ) );
|
||||
wp_set_script_translations( 'chrnx-editor-podcast', 'chrnx', get_theme_file_path( 'languages' ) );
|
||||
wp_set_script_translations( 'chrnx-editor-project', 'chrnx', get_theme_file_path( 'languages' ) );
|
||||
wp_set_script_translations( 'chrnx-editor-track', 'chrnx', get_theme_file_path( 'languages' ) );
|
||||
}
|
||||
add_action( 'enqueue_block_editor_assets', 'chrnx_enqueue_editor_assets' );
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Project post metadata.
|
||||
*
|
||||
* @package CHRNX
|
||||
*/
|
||||
|
||||
/**
|
||||
* Require permission to edit the post owning project metadata.
|
||||
*
|
||||
* @param bool $allowed Previously calculated permission.
|
||||
* @param string $meta_key Metadata key.
|
||||
* @param int $post_id Post ID.
|
||||
* @return bool Whether the current user can edit the post.
|
||||
*/
|
||||
function chrnx_auth_project_meta( $allowed, $meta_key, $post_id ) {
|
||||
return current_user_can( 'edit_post', $post_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register project metadata for posts.
|
||||
*/
|
||||
function chrnx_register_project_meta() {
|
||||
register_post_meta(
|
||||
'post',
|
||||
'chrnx_project_featured',
|
||||
array(
|
||||
'type' => 'boolean',
|
||||
'single' => true,
|
||||
'default' => false,
|
||||
'show_in_rest' => array( 'schema' => array( 'type' => 'boolean' ) ),
|
||||
'sanitize_callback' => 'rest_sanitize_boolean',
|
||||
'auth_callback' => 'chrnx_auth_project_meta',
|
||||
)
|
||||
);
|
||||
}
|
||||
add_action( 'init', 'chrnx_register_project_meta' );
|
||||
+77
-10
@@ -262,6 +262,59 @@ function chrnx_get_featured_story_ids( int $limit = 3 ): array {
|
||||
return $selected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select projects for the Selected work stage: hand-picked first, then recent.
|
||||
*
|
||||
* Sticky already belongs to the home featured stories, so the editorial choice
|
||||
* lives in its own per-post flag instead of competing for the same signal.
|
||||
*
|
||||
* @param int $limit Maximum projects, bounded to 12.
|
||||
* @return int[] Selected project post IDs.
|
||||
*/
|
||||
function chrnx_get_selected_project_ids( int $limit = 3 ): array {
|
||||
$limit = min( 12, max( 0, $limit ) );
|
||||
if ( 0 === $limit ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$topic_query = array(
|
||||
array(
|
||||
'taxonomy' => 'chrnx_topic',
|
||||
'field' => 'slug',
|
||||
'terms' => 'projects',
|
||||
),
|
||||
);
|
||||
|
||||
$selected = chrnx_get_eligible_editorial_post_ids(
|
||||
array(
|
||||
'posts_per_page' => $limit,
|
||||
'tax_query' => $topic_query,
|
||||
'meta_query' => array(
|
||||
array(
|
||||
'key' => 'chrnx_project_featured',
|
||||
'value' => '1',
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
$remaining = $limit - count( $selected );
|
||||
if ( $remaining > 0 ) {
|
||||
$selected = array_merge(
|
||||
$selected,
|
||||
chrnx_get_eligible_editorial_post_ids(
|
||||
array(
|
||||
'posts_per_page' => $remaining,
|
||||
'post__not_in' => $selected,
|
||||
'tax_query' => $topic_query,
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $selected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a request taxonomy slug against an existing editorial term.
|
||||
*
|
||||
@@ -624,15 +677,20 @@ function chrnx_get_related_post_ids( int $post_id, int $limit = 3 ): array {
|
||||
*/
|
||||
function chrnx_get_topic_art_asset( string $topic_slug ): string {
|
||||
$mapping = array(
|
||||
'research' => 'alter-ego-research.png',
|
||||
'code' => 'alter-ego-code.png',
|
||||
'literature' => 'alter-ego-literature.png',
|
||||
'music' => 'the-no-names-musician-cutout.png',
|
||||
'music-collage' => 'the-no-names-collage.jpeg',
|
||||
'podcast-frequency' => 'podcast-frequency-grunge.png',
|
||||
'podcasts' => 'alter-ego-podcasts.png',
|
||||
'life' => 'alter-ego-life.png',
|
||||
'gaming' => 'alter-ego-gaming-half-body.png',
|
||||
'research' => 'alter-ego-research.png',
|
||||
'code' => 'alter-ego-code.png',
|
||||
'projects' => 'alter-ego-code.png',
|
||||
'literature' => 'alter-ego-literature.png',
|
||||
'music' => 'the-no-names-musician-cutout.png',
|
||||
'music-collage' => 'the-no-names-collage.jpeg',
|
||||
'podcast-frequency' => 'podcast-frequency-grunge.png',
|
||||
'about-grunge' => 'about-grunge.png',
|
||||
'placeholder-post' => 'placeholder-post.png',
|
||||
'placeholder-release' => 'placeholder-release.png',
|
||||
'projects-grunge' => 'projects-grunge.png',
|
||||
'podcasts' => 'alter-ego-podcasts.png',
|
||||
'life' => 'alter-ego-life.png',
|
||||
'gaming' => 'alter-ego-gaming-half-body.png',
|
||||
);
|
||||
return isset( $mapping[ $topic_slug ] ) ? 'assets/images/' . $mapping[ $topic_slug ] : '';
|
||||
}
|
||||
@@ -648,9 +706,18 @@ function chrnx_get_topic_art_dimensions( string $topic_slug ): array {
|
||||
return array();
|
||||
}
|
||||
|
||||
if ( 'podcast-frequency' === $topic_slug ) {
|
||||
// The landscape atmosphere backgrounds share one intrinsic size.
|
||||
if ( in_array( $topic_slug, array( 'podcast-frequency', 'about-grunge', 'projects-grunge' ), true ) ) {
|
||||
return array( 1536, 1024 );
|
||||
}
|
||||
|
||||
if ( 'placeholder-post' === $topic_slug ) {
|
||||
return array( 1440, 960 );
|
||||
}
|
||||
|
||||
if ( 'placeholder-release' === $topic_slug ) {
|
||||
return array( 1536, 1536 );
|
||||
}
|
||||
|
||||
return 'gaming' === $topic_slug ? array( 1024, 1536 ) : array( 1122, 1402 );
|
||||
}
|
||||
+26
-5
@@ -19,6 +19,7 @@ function chrnx_get_editorial_taxonomies() {
|
||||
'terms' => array(
|
||||
'research' => __( 'Research', 'chrnx' ),
|
||||
'code' => __( 'Code', 'chrnx' ),
|
||||
'projects' => __( 'Projects', 'chrnx' ),
|
||||
'literature' => __( 'Literature', 'chrnx' ),
|
||||
'music' => __( 'Music', 'chrnx' ),
|
||||
'podcasts' => __( 'Podcasts', 'chrnx' ),
|
||||
@@ -43,6 +44,16 @@ function chrnx_get_editorial_taxonomies() {
|
||||
'silicon-ranch' => __( 'Silicon Ranch', 'chrnx' ),
|
||||
),
|
||||
),
|
||||
'chrnx_release' => array(
|
||||
'singular' => __( 'Release', 'chrnx' ),
|
||||
'plural' => __( 'Releases', 'chrnx' ),
|
||||
'rest_base' => 'release',
|
||||
'terms' => array(
|
||||
'el-hermoso-caos' => __( 'El Hermoso Caos que habita en mi cabeza', 'chrnx' ),
|
||||
'ando-bien-arriba' => __( 'Ando Bien Arriba', 'chrnx' ),
|
||||
'aqui-se-rompio-una-jerga' => __( 'Aquí se Rompió una Jerga', 'chrnx' ),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -91,11 +102,21 @@ function chrnx_seed_editorial_terms() {
|
||||
}
|
||||
|
||||
foreach ( $definition['terms'] as $slug => $name ) {
|
||||
if ( ! term_exists( $slug, $taxonomy_name ) ) {
|
||||
$result = wp_insert_term( $name, $taxonomy_name, array( 'slug' => $slug ) );
|
||||
if ( is_wp_error( $result ) || false === $result ) {
|
||||
chrnx_store_editorial_notice( '', 'vocabulary_setup_failed' );
|
||||
}
|
||||
/*
|
||||
* term_exists() reads a cache that is not always warm during theme
|
||||
* activation, which let a second activation insert duplicates with
|
||||
* a "-2" slug. Ask the taxonomy directly, by slug and by name.
|
||||
*/
|
||||
if ( get_term_by( 'slug', $slug, $taxonomy_name ) instanceof WP_Term ) {
|
||||
continue;
|
||||
}
|
||||
if ( get_term_by( 'name', $name, $taxonomy_name ) instanceof WP_Term ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$result = wp_insert_term( $name, $taxonomy_name, array( 'slug' => $slug ) );
|
||||
if ( is_wp_error( $result ) || false === $result ) {
|
||||
chrnx_store_editorial_notice( '', 'vocabulary_setup_failed' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user