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

Change default behavior of Homepage Posts and Carousel blocks to include posts in subcategories #1482

Merged
merged 9 commits into from
Jun 28, 2023

Conversation

DennisNDean
Copy link
Contributor

@DennisNDean DennisNDean commented Jun 26, 2023

All Submissions:

Changes proposed in this Pull Request:

Change the default behavior of the Homepage Posts and Carousel blocks to include posts in subcategories of the selected categories. Added a toggle under the category picker to switch this behavior off.

Generally speaking, this is more in line with how Wordpress treats parent/child categories, where a query for the parent category is inclusive of posts in the child categories, and seems more intuitive.

Closes #207

How to test the changes in this Pull Request:

  1. Create a category with one or more child categories (i.e. Food > Tacos)
  2. Categorize some posts into the parent category (i.e. Food)
  3. Categorize some posts into the child category, but do not explicitly categorize them into the parent category (i.e. Tacos, but not Food)
  4. Create a new page and add a Homepage Posts block
  5. Under Display Settings, filter by the parent category (i.e. Food)
  6. Observe that posts from the child category are also included
  7. Toggle "Include subcategories" off, observe that now only posts from the parent category are displayed
  8. Do the same with the Carousel block

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Dennis Dean and others added 2 commits June 26, 2023 08:57
… include subcategories of the selected categories. Added a toggle below the categories picker to turn this on and off.
@DennisNDean DennisNDean requested a review from a team as a code owner June 26, 2023 16:29
@dkoo
Copy link
Contributor

dkoo commented Jun 26, 2023

@DennisNDean thanks for your contribution! We'll put this in our queue to test, and will get back to you shortly.

Copy link
Member

@miguelpeixe miguelpeixe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution, @DennisNDean!

It's working as described and the code looks good. A few minor changes are required before we are able to merge. They are commented inline, please let me know if you have any questions.

$args = array(
$authors = isset( $attributes['authors'] ) ? $attributes['authors'] : array();
$categories = isset( $attributes['categories'] ) ? $attributes['categories'] : array();
$include_subcategories = isset( $attributes['includeSubcategories'] ) ? intval($attributes['includeSubcategories']) : false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint: there should be a space before and after the arguments for intval():
intval( $attributes['includeSubcategories'] );

This is also the case for other instances in this file, see the spacing and indentation in the conditional statement, foreach loop, etc between lines 670 and 677.

You can find more information on WP coding standards here: https://github.com/WordPress/WordPress-Coding-Standards

src/blocks/carousel/edit.js Outdated Show resolved Hide resolved
@DennisNDean
Copy link
Contributor Author

Awesome, thank you — those changes have been made.

Comment on lines 631 to 641
$authors = isset( $attributes['authors'] ) ? $attributes['authors'] : array();
$categories = isset( $attributes['categories'] ) ? $attributes['categories'] : array();
$include_subcategories = isset( $attributes['includeSubcategories'] ) ? intval( $attributes['includeSubcategories'] ) : false;
$tags = isset( $attributes['tags'] ) ? $attributes['tags'] : array();
$custom_taxonomies = isset( $attributes['customTaxonomies'] ) ? $attributes['customTaxonomies'] : array();
$tag_exclusions = isset( $attributes['tagExclusions'] ) ? $attributes['tagExclusions'] : array();
$category_exclusions = isset( $attributes['categoryExclusions'] ) ? $attributes['categoryExclusions'] : array();
$specific_posts = isset( $attributes['specificPosts'] ) ? $attributes['specificPosts'] : array();
$posts_to_show = intval( $attributes['postsToShow'] );
$specific_mode = isset( $attributes['specificMode'] ) ? intval( $attributes['specificMode'] ) : false;
$args = array(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's a double-space on $include_subcategories =. Can you trim the extra space off from these lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, that's fixed, thank you

foreach ( $categories as $parent ) {
$children[] = get_categories(array('child_of'=> $parent));
foreach ( $children[0] as $child ) {
$categories[] = $child->term_id;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a tab here

includes/class-newspack-blocks.php Outdated Show resolved Hide resolved
Co-authored-by: Miguel Peixe <miguel@peixe.co>
@miguelpeixe
Copy link
Member

Thank you for the revisions, @DennisNDean!

@miguelpeixe miguelpeixe merged commit faa8734 into Automattic:master Jun 28, 2023
miguelpeixe added a commit that referenced this pull request Jun 28, 2023
matticbot pushed a commit that referenced this pull request Jul 7, 2023
# [1.73.0-alpha.1](v1.72.0...v1.73.0-alpha.1) (2023-07-07)

### Features

* add updated translation files ([#1486](#1486)) ([3a44410](3a44410))
* allow Homepage Posts and Carousel blocks to include subcategories ([#1482](#1482)) ([faa8734](faa8734))
* **modal-checkout:** render order details under different conditions ([#1485](#1485)) ([ae62734](ae62734))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.73.0-alpha.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Jul 17, 2023
# [1.73.0](v1.72.2...v1.73.0) (2023-07-17)

### Features

* add updated translation files ([#1486](#1486)) ([3a44410](3a44410))
* allow Homepage Posts and Carousel blocks to include subcategories ([#1482](#1482)) ([faa8734](faa8734))
* **modal-checkout:** render order details under different conditions ([#1485](#1485)) ([ae62734](ae62734))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.73.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Article Block: Get articles from the sub-categories as well?
4 participants