Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the homepage top post translatable. #103

Merged
merged 3 commits into from
May 13, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 64 additions & 1 deletion wp-content/themes/caribbean/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,67 @@ function caribbean_after_header() {
echo '</div>';

}
add_action( 'largo_header_after_largo_header', 'caribbean_after_header' );
add_action( 'largo_header_after_largo_header', 'caribbean_after_header' );

/**
* Reimplement largo_home_single_top() but with WPML compatibility.
*
* @link https://wpml.org/forums/topic/get_posts-by-language-and-suppress_filters-false-issue/
* @link https://github.com/INN/largo/blob/v0.6.4/homepages/homepage.php#L93
*/
function caribbean_home_single_top() {
$big_story = null;
benlk marked this conversation as resolved.
Show resolved Hide resolved

// Cache the terms
$homepage_feature_term = get_term_by( 'slug', 'homepage-featured', 'prominence' );
$top_story_term = get_term_by( 'slug', 'top-story', 'prominence' );

// Get the posts that are both in 'Homepage Featured' and 'Homepage Top Story'
$top_story_posts = get_posts(array(
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'prominence',
'field' => 'term_id',
'terms' => $top_story_term->term_id
),
),
'posts_per_page' => 1,
'suppress_filters' => false,
));

if ( !empty( $top_story_posts ) ) {
return $top_story_posts[0];
}

// Fallback: get the posts that are in "Homepage Featured" but not "Homepage Top Story"
$homepage_featured_posts = get_posts(array(
'tax_query' => array(
array(
'taxonomy' => 'prominence',
'field' => 'term_id',
'terms' => $homepage_feature_term->term_id
)
),
'posts_per_page' => 1,
'suppress_filters' => false,
));

if ( !empty( $homepage_featured_posts ) ) {
return $homepage_featured_posts[0];
}

// Double fallback: Get the most recent post
$posts = get_posts( array(
'orderby' => 'date',
'order' => 'DESC',
'posts_per_page' => 1,
'suppress_filters' => false,
) );

if ( !empty( $posts ) ) {
return $posts[0];
}

return null;
}
2 changes: 1 addition & 1 deletion wp-content/themes/caribbean/homepages/template.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
global $shown_ids;

$topstory = largo_home_single_top();
$topstory = caribbean_home_single_top();
$shown_ids[] = $topstory->ID;

$featured_stories = largo_home_featured_stories( 3 );
Expand Down