/** * Subtle highlight for sponsored (branded content) posts in JNews homepage modules. * MURAI.MY VARIANT. * * Drop this into the child theme's functions.php (or require it from there). * * Murai's homepage uses the same two modules as Hype for the pinned-post row: * - desktop: block 22 (jeg_pl_md_5, 3 cards, 30px gutter inside each card) - same as Varnam * - mobile: block 18 (jeg_pl_lg_2, 150px floated thumb + text, full-bleed, hairline under each row) * The CSS is identical to the Hype file. * * Note: Murai also has an editorial category named "Spotlight". The card tag is * kept as "Spotlight" for consistency with the other sites; change it with: * add_filter( 'jnews_sponsored_card_tag', fn() => 'Tajaan' ); * * Driven entirely by the JNews "Sponsored Post" metabox on the post: * - Sponsored Post = on * - Sponsored Post Label = e.g. "Presented by" * - Sponsored Post Name = e.g. the partner's name * A sponsored post only gets the treatment inside modules that have * "Include Pinned Post" enabled (the sticky_post module option). In every other * module it renders as a normal card. * * Per-site colours: add_filter( 'jnews_sponsored_card_colors', fn( $c ) => [ 'tint' => '#…', 'accent' => '#…' ] + $c ); */ /** * Remember whether the module currently being built has "Include Pinned Post" on. * * jnews_module_attr_global fires in ModuleViewAbstract::build_module() right * before render_module(), once per module, so the flag always reflects the * module whose cards are being rendered. */ function jnews_sponsored_track_module( $attr ) { $GLOBALS['jnews_sponsored_module_pinned'] = isset( $attr['sticky_post'] ) && in_array( $attr['sticky_post'], array( 'yes', 'true' ), true ); return $attr; } add_filter( 'jnews_module_attr_global', 'jnews_sponsored_track_module' ); /** * True when $post_id is a sponsored post being rendered inside a pinned-post module. */ function jnews_sponsored_card_applies( $post_id ) { return ! empty( $GLOBALS['jnews_sponsored_module_pinned'] ) && jnews_get_metabox_value( 'jnews_single_post.sponsored_post', null, $post_id ); } /** * Add a `jnews-sponsored` class to module cards of sponsored posts. * * The parent wraps jnews_post_class() in function_exists(), and the child * functions.php loads first, so this copy replaces it. Body is the parent's, * plus the sponsored check. */ function jnews_post_class( $class = '', $post_id = null ) { $post_type = get_post_type( $post_id ); if ( $post_type && post_type_supports( $post_type, 'post-formats' ) ) { $post_format = get_post_format( $post_id ); if ( $post_format && ! is_wp_error( $post_format ) ) { $class .= ' format-' . sanitize_html_class( $post_format ); } else { $class .= ' format-standard'; } } if ( jnews_sponsored_card_applies( $post_id ) ) { $class .= ' jnews-sponsored'; } return 'class="' . $class . '"'; } /** * Prepend the " /