/** * [mn_network_posts count="6"] * * Aggregates the most recent posts from all public subsites in the Mulembe * Nation network and renders them as a grid matching .mn-posts-section CSS. * * Uses a 5-minute transient to avoid switch_to_blog() storms on every page load. * * Added: 2026-05-22 — Task 7 (fix network post loop on main site) */ add_shortcode( 'mn_network_posts', function( $atts ) { $atts = shortcode_atts( [ 'count' => 6 ], $atts ); $count = max( 1, min( 30, intval( $atts['count'] ) ) ); $cache_key = 'mn_network_posts_' . $count; $cached = get_transient( $cache_key ); if ( $cached !== false ) { return $cached; } // Public subsites (blog IDs from multisite registration) // 1 = main aggregator (skip), 2=bukusu, 4=food, 5=politics, 6=business, // 7=sport, 9=travel. 3=enyanga and 8=findyourfamily are private. $blog_ids = [ 2, 4, 5, 6, 7, 9 ]; $all_posts = []; foreach ( $blog_ids as $blog_id ) { switch_to_blog( $blog_id ); $posts = get_posts( [ 'numberposts' => $count, 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'DESC', ] ); foreach ( $posts as $post ) { $all_posts[] = [ 'date' => strtotime( $post->post_date_gmt ), 'title' => get_the_title( $post ), 'url' => get_permalink( $post ), 'excerpt' => wp_trim_words( get_the_excerpt( $post ), 15 ), 'thumb' => get_the_post_thumbnail_url( $post, 'medium' ), 'blog_id' => $blog_id, 'blog_name' => get_bloginfo( 'name' ), ]; } restore_current_blog(); } // Merge: sort by date descending, then slice usort( $all_posts, function( $a, $b ) { return $b['date'] - $a['date']; } ); $all_posts = array_slice( $all_posts, 0, $count ); if ( empty( $all_posts ) ) { return '

No recent posts from the network.

'; } // Render matching wp-block-post-template grid $out = ''; set_transient( $cache_key, $out, 5 * MINUTE_IN_SECONDS ); return $out; }); Mulembe Nation — East Africa Intelligence. Politics, Business, Culture, Sport.

East Africa Intelligence. From the Great Lakes.

Data-driven reporting, governance indices, cultural knowledge, and original analysis across Kenya, Uganda, Tanzania, Rwanda, Burundi, and the DRC.

Mulembe Nation is an intelligence platform built on the knowledge systems of the Great Lakes region. About us · Code of Ethics · Submit a Tip

About Mulembe Nation

What is Mulembe Nation?

Mulembe Nation is an intelligence platform for East Africa and the Great Lakes region. We publish data-driven analysis, governance indices, cultural knowledge, and original reporting across politics, business, sport, travel, food, and Luhya language and culture. We are based in Nairobi, Kenya and have been publishing since 2016.

What does Mulembe mean?

Mulembe is a Luhya word meaning both peace and greeting. Its deeper meaning invokes a social contract: we see each other, we acknowledge each other’s humanity, and we commit to resolving disputes through dialogue rather than violence. It is the standard we hold governance and community to across everything we publish.

How do I contribute data or submit a tip?

We welcome data submissions, document tips, and community knowledge contributions across all our verticals. Visit our Submit a Tip page or email lab@mulembenation.co.ke. Source protection is available for sensitive submissions.