Skip to content

Commit

Permalink
post grid fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
farhan-shafi committed Jul 3, 2024
1 parent 8c6dd1b commit a9c6c77
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion dist/blocks.build.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('lodash', 'moment', 'react', 'react-dom', 'wp-api', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-keycodes', 'wp-notices', 'wp-primitives', 'wp-url'), 'version' => 'e2d7b1de3e4083df9901');
<?php return array('dependencies' => array('lodash', 'moment', 'react', 'react-dom', 'wp-api', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-keycodes', 'wp-notices', 'wp-primitives', 'wp-url'), 'version' => '509b5aa597c568a73a12');
4 changes: 3 additions & 1 deletion dist/blocks.build.js
Original file line number Diff line number Diff line change
Expand Up @@ -72835,15 +72835,17 @@ function PostGridBlock(props) {
readMoreText = _props$attributes.readMoreText,
postLayout = _props$attributes.postLayout,
columns = _props$attributes.columns,
preservePostImageAspectRatio = _props$attributes.preservePostImageAspectRatio,
postTitleTag = _props$attributes.postTitleTag,
isEqualHeight = _props$attributes.isEqualHeight,
className = props.className,
posts = props.posts;
var PostTag = postTitleTag;
var equalHeightClass = isEqualHeight ? " is-equal-height " : "";
var isPreservePostImageAspectRatio = preservePostImageAspectRatio ? " preserve-post-image-aspect-ratio " : "";
var styles = (0,_get_styles__WEBPACK_IMPORTED_MODULE_2__.getStyles)(props.attributes);
return /*#__PURE__*/React.createElement("section", {
className: "".concat(className ? "".concat(className, " ") : "").concat(equalHeightClass, "ub-block-post-grid"),
className: "".concat(className ? "".concat(className, " ") : "").concat(equalHeightClass).concat(isPreservePostImageAspectRatio, "ub-block-post-grid"),
style: styles
}, /*#__PURE__*/React.createElement("div", {
className: "ub-post-grid-items ".concat(postLayout === "list" ? "is-list" : "is-grid columns-".concat(columns))
Expand Down
2 changes: 1 addition & 1 deletion dist/blocks.build.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/blocks.style.build.css

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ That's it. You're done!

= 3.2.1 =

* FIX: Post Excerpt null warning in post grid block.
* FIX: Post image preserve aspect ratio not working properly on frontend.
* IMPROVE: Run counter when it visible on the screen in the counter block.
* IMPROVE: Image width in image slider.
* NEW: Spacing between counter and label in counter block.
Expand Down
10 changes: 6 additions & 4 deletions src/blocks/post-grid/block.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function ub_render_post_grid_block( $attributes, $content, $block ){
$post_grid .= sprintf(
'<div class="ub-block-post-grid-image"><a href="%1$s" rel="bookmark" aria-hidden="true" tabindex="-1">%2$s</a></div>',
esc_url( get_permalink( $post_id ) ),
wp_get_attachment_image( $post_thumb_id, array($attributes['postImageWidth'], $attributes['preservePostImageAspectRatio'] ? 0 : $attributes['postImageHeight']) )//use array
wp_get_attachment_image( $post_thumb_id, array($attributes['postImageWidth'], $attributes['preservePostImageAspectRatio'] ? 0 : $attributes['postImageHeight']) )//use array
);
}

Expand Down Expand Up @@ -182,7 +182,7 @@ function ub_render_post_grid_block( $attributes, $content, $block ){
$excerpt = null;
}

if ( isset( $attributes['checkPostExcerpt'] ) && $attributes['checkPostExcerpt'] ) {
if ( isset( $attributes['checkPostExcerpt'] ) && $attributes['checkPostExcerpt'] && !empty( $excerpt )) {
$post_grid .= sprintf('<div class="ub-block-post-grid-excerpt-text">%1$s</div>', wp_kses_post( $excerpt ));
}

Expand Down Expand Up @@ -238,15 +238,17 @@ function ub_render_post_grid_block( $attributes, $content, $block ){

$section_tag = 'section';
$is_equal_height = isset($attributes['isEqualHeight']) && $attributes['isEqualHeight'] ? " is-equal-height " : "";
$is_preserve_post_image_aspect_ratio = isset($attributes['preservePostImageAspectRatio']) && $attributes['preservePostImageAspectRatio'] ? " preserve-post-image-aspect-ratio " : "";

/* Output the post markup */
$block_content = sprintf(
'<%1$s class="%2$s%5$s"><div class="%3$s">%4$s</div></%1$s>',
'<%1$s class="%2$s%5$s%6$s"><div class="%3$s">%4$s</div></%1$s>',
$section_tag,
esc_attr( $class ),
esc_attr( $grid_class ),
$post_grid,
esc_attr($is_equal_height)
esc_attr($is_equal_height),
$is_preserve_post_image_aspect_ratio
);
return $block_content;
}
Expand Down
6 changes: 5 additions & 1 deletion src/blocks/post-grid/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default function PostGridBlock(props) {
readMoreText,
postLayout,
columns,
preservePostImageAspectRatio,
postTitleTag,
isEqualHeight,
},
Expand All @@ -27,11 +28,14 @@ export default function PostGridBlock(props) {

const PostTag = postTitleTag;
const equalHeightClass = isEqualHeight ? " is-equal-height " : "";
const isPreservePostImageAspectRatio = preservePostImageAspectRatio
? " preserve-post-image-aspect-ratio "
: "";

const styles = getStyles(props.attributes);
return (
<section
className={`${className ? `${className} ` : ""}${equalHeightClass}ub-block-post-grid`}
className={`${className ? `${className} ` : ""}${equalHeightClass}${isPreservePostImageAspectRatio}ub-block-post-grid`}
style={styles}
>
<div
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/post-grid/style.css

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/blocks/post-grid/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
}
margin: 0 0 1.2em 0;
position: relative;
&.preserve-post-image-aspect-ratio {
.ub-post-grid-items {
article {
.ub-block-post-grid-image {
img {
height: auto;
}
}
}
}
}
.ub-post-grid-items {
align-items: flex-start;
row-gap: var(--ub-post-grid-row-gap, 32px);
Expand Down

0 comments on commit a9c6c77

Please sign in to comment.