Skip to content

Commit

Permalink
Main: Display news posts from the main WordPress.org news blog if the…
Browse files Browse the repository at this point in the history
… site has no news.

This is primarily for use on the WordPress.org homepage, which has to fetch news from the /news/ subsite.


git-svn-id: https://meta.svn.wordpress.org/sites/trunk@11414 74240141-8908-4e6f-9713-ba540dce6ec7
  • Loading branch information
dd32 committed Jan 6, 2022
1 parent 3032424 commit 3f93d90
Showing 1 changed file with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
$swag_class = $showcase ? 'col-4' : 'col-2';
$user_class = $showcase ? 'col-12' : 'col-2';

$cdn_domain = defined( 'WPORG_SANDBOXED' ) && WPORG_SANDBOXED ? 's-origin.wordpress.org' : 's.w.org';

get_header( 'wporg' );
?>
<header id="masthead" class="site-header" role="banner">
Expand Down Expand Up @@ -165,23 +163,47 @@

<div id="home-below" class="home-below row gutters">
<div class="col-4">
<h4><a href="<?php echo get_permalink( get_option( 'page_for_posts' ) ); ?>"><?php _e( 'News From Our Blog', 'wporg' ); ?></a></h4>

<?php
$featured = new \WP_Query( [
$switched = false;
$news_blog_url = get_permalink( get_option( 'page_for_posts' ) );
$featured_args = [
'posts_per_page' => 1,
'post_status' => 'publish',
'ignore_sticky_posts' => true,
'no_found_rows' => true,
] );

while ( $featured->have_posts() ) :
];
$featured = new \WP_Query( $featured_args );

// Fetch posts from the English News blog if this site doesn't have any.
if ( ! $featured->have_posts() && defined( 'WPORG_NEWS_BLOGID' ) ) {
$switched = switch_to_blog( WPORG_NEWS_BLOGID );
$featured = new \WP_Query( $featured_args );
$news_blog_url = home_url( '/' );
}

printf(
'<h4><a href="%s">%s</a></h4>',
esc_url( $news_blog_url ),
__( 'News From Our Blog', 'wporg' )
);

// Forcibly hide all Jetpack sharing buttons.
add_filter( 'sharing_show', '__return_false' );

while ( $featured->have_posts() ) {
$featured->the_post();

the_title( sprintf( '<h5><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h5>' );
echo '<div class="entry-summary">' . apply_filters( 'the_excerpt', get_the_excerpt() ) . '</div>';
endwhile;
}

remove_filter( 'sharing_show', '__return_false' );

wp_reset_postdata();

if ( $switched ) {
restore_current_blog();
}
?>
</div>

Expand Down Expand Up @@ -268,7 +290,7 @@

foreach ( array_rand( $user_links, 3 ) as $slug ) :
printf(
'<li><a href="%1$s"><img src="https://'. $cdn_domain .'/images/notableusers/%2$s-2x.png?version=2" alt="%2$s" width="130" height="57" /></a></li>',
'<li><a href="%1$s"><img src="https://s.w.org/images/notableusers/%2$s-2x.png?version=2" alt="%2$s" width="130" height="57" /></a></li>',
$user_links[ $slug ],
$slug
);
Expand Down

0 comments on commit 3f93d90

Please sign in to comment.