Skip to content

Commit

Permalink
Merge pull request #4139 from Codeinwp/fix/blog-width-feature-image
Browse files Browse the repository at this point in the history
Fix: use container full width when featured image is missing
  • Loading branch information
preda-bogdan authored Nov 28, 2023
2 parents 82d0c9a + fb7925c commit ae14f1c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,13 @@
"neve_blog_covers_text_color": "#bada55",
"neve_grid_layout": "{\"desktop\":2,\"tablet\":2,\"mobile\":2}",
"neve_enable_masonry": true
},
"archive4": {
"neve_blog_archive_layout": "default",
"neve_post_excerpt_length": 15,
"neve_post_thumbnail_box_shadow": 4,
"neve_post_content_ordering": "[\"title-meta\", \"excerpt\"]",
"neve_post_meta_ordering": "[\"date\", \"author\", \"category\"]",
"neve_pagination_type": "number"
}
}
19 changes: 19 additions & 0 deletions e2e-tests/specs/customizer/layout/blog-archive-settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,22 @@ test.describe('Blog/Archive 3 / Covers Layout', () => {
}
});
});

test.describe('Blog/Archive 4 / Default Layout', () => {
test.beforeAll(async ({ request, baseURL }) => {
await setCustomizeSettings('defaultLayout', data.archive4, {
request,
baseURL,
});
});

test('Tests If Post Thumbnail Class Is Removed', async ({ page }) => {
await page.goto('/?test_name=defaultLayout');

await page.waitForSelector('article.post');

expect(
await page.locator('article.post.has-post-thumbnail').count()
).toEqual(0);
});
});
56 changes: 35 additions & 21 deletions inc/views/template_parts.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ function () use ( $posts_to_exclude ) {
* Render the post.
*/
public function render_post() {

$args = array(
'post_id' => 'post-' . get_the_ID(),
'post_class' => $this->post_class(),
Expand Down Expand Up @@ -210,6 +211,12 @@ protected function post_class( $post_id = null, $additional = '' ) {
$class .= ' nv-non-grid-article';
}
}

// Filter the Core classes for missing components.
$is_thumbnail_inactive = ! in_array( 'thumbnail', $this->get_ordered_components(), true );
if ( $is_thumbnail_inactive ) {
$class = str_replace( 'has-post-thumbnail', '', $class );
}

$class .= ' ' . $additional;
return $class;
Expand All @@ -227,16 +234,12 @@ private function get_article_inner_content( $post_id = null ) {
$layout = $this->get_layout();
$is_featured_post = $post_id !== null;
$featured_template = in_array( $layout, [ 'alternative', 'default', 'grid' ], true ) ? 'tp1' : 'tp2';
$default_order = array(
'thumbnail',
'title-meta',
'excerpt',
);
$order = json_decode( get_theme_mod( 'neve_post_content_ordering', wp_json_encode( $default_order ) ) );

$is_thumbnail_active = in_array( 'thumbnail', $this->get_ordered_components(), true );

if ( in_array( $layout, [ 'alternative', 'default' ], true ) || ( $is_featured_post && $featured_template === 'tp1' ) ) {
$markup .= '<div class="' . esc_attr( $layout ) . '-post nv-ft-wrap">';
if ( in_array( 'thumbnail', $order, true ) || ( $is_featured_post && $featured_template === 'tp1' ) ) {
if ( $is_thumbnail_active || ( $is_featured_post && $featured_template === 'tp1' ) ) {
$markup .= $this->get_post_thumbnail( $post_id );
}
$markup .= '<div class="non-grid-content ' . esc_attr( $layout ) . '-layout-content">';
Expand All @@ -250,7 +253,7 @@ private function get_article_inner_content( $post_id = null ) {
if ( $layout === 'covers' ) {
$markup .= '<div class="cover-post nv-ft-wrap">';
$markup .= '<div class="cover-overlay"></div>';
if ( in_array( 'thumbnail', $order, true ) ) {
if ( $is_thumbnail_active ) {
$markup .= $this->get_post_thumbnail( $post_id, true );
}
$markup .= '<div class="inner">';
Expand Down Expand Up @@ -452,24 +455,18 @@ public function link_excerpt_more( $moretag, $post_id = null ) {
* @return string
*/
private function get_ordered_content_parts( $exclude_thumbnail = false, $post_id = null ) {
$markup = '';
$default_order = array(
'thumbnail',
'title-meta',
'excerpt',
);
$markup = '';
$ordered_components = $this->get_ordered_components( true );

$order = get_theme_mod( 'neve_post_content_ordering', wp_json_encode( $default_order ) );
$order = json_decode( $order, true );
if ( $post_id !== null && in_array( 'thumbnail', $order, true ) ) {
$key = array_search( 'thumbnail', $order );
if ( $post_id !== null && in_array( 'thumbnail', $ordered_components, true ) ) {
$key = array_search( 'thumbnail', $ordered_components );
if ( $key !== false ) {
unset( $order[ $key ] );
unset( $ordered_components[ $key ] );
}
array_unshift( $order, 'thumbnail' );
array_unshift( $ordered_components, 'thumbnail' );
}

foreach ( $order as $content_bit ) {
foreach ( $ordered_components as $content_bit ) {
switch ( $content_bit ) {
case 'thumbnail':
if ( $exclude_thumbnail ) {
Expand Down Expand Up @@ -506,4 +503,21 @@ private function get_ordered_content_parts( $exclude_thumbnail = false, $post_id

return $markup;
}

/**
* Get components (thumbnail, title, meta, excerpt) in the order they are set in the Customizer.
*
* @param bool $associative Whether to return an associative array or not.
*
* @return mixed
*/
public function get_ordered_components( $associative = false ) {
$default_ordered_components = array(
'thumbnail',
'title-meta',
'excerpt',
);

return json_decode( get_theme_mod( 'neve_post_content_ordering', wp_json_encode( $default_ordered_components ) ), $associative );
}
}

0 comments on commit ae14f1c

Please sign in to comment.