diff --git a/inc/vk-blocks/view/class-vk-blocks-postlist.php b/inc/vk-blocks/view/class-vk-blocks-postlist.php index 44e28ec4e..47c2af3d4 100644 --- a/inc/vk-blocks/view/class-vk-blocks-postlist.php +++ b/inc/vk-blocks/view/class-vk-blocks-postlist.php @@ -217,6 +217,26 @@ public static function get_loop_query( $attributes ) { if ( ! empty( $date_query ) ) { $args['date_query'] = $date_query; } + + $sticky_posts_mode = isset( $attributes['stickyPosts'] ) ? $attributes['stickyPosts'] : 'include'; + + switch ( $sticky_posts_mode ) { + case 'include': + $args['ignore_sticky_posts'] = false; + break; + + case 'exclude': + $args['post__not_in'] = array_merge( isset( $args['post__not_in'] ) ? $args['post__not_in'] : array(), get_option( 'sticky_posts' ) ); + break; + + case 'only': + $sticky_posts = get_option( 'sticky_posts' ); + $args['post__in'] = ! empty( $sticky_posts ) ? $sticky_posts : array( 0 ); + $args['posts_per_page'] = count( $args['post__in'] ); + $args['orderby'] = $attributes['orderby']; + break; + } + $args = apply_filters( 'vk_blocks_post_list_query_args', $args, $attributes ); return new WP_Query( $args ); diff --git a/readme.txt b/readme.txt index a09eaad39..d89c39b4f 100644 --- a/readme.txt +++ b/readme.txt @@ -108,6 +108,9 @@ e.g. == Changelog == + +[ Add function ][ Post List (Pro) / Post List Slider (Pro) ] Added the ability to set sticky posts to display. + = 1.96.2 = [ Bug fix ][ Post list (Pro) / Post list slider (Pro) / Tab (Pro) / Slider ] Fixed errors occurring regardless of whether the editing screen environment is in an iframe and improved the stability of feature performance. [ Bug fix ][ Post list (Pro) / Post list slider (Pro) ] Fixed the text displayed when no posts are available by removing the 's' notation and standardizing the first letter to lowercase. diff --git a/src/blocks/_pro/post-list-slider/block.json b/src/blocks/_pro/post-list-slider/block.json index 5c952261a..0b9a1af0e 100644 --- a/src/blocks/_pro/post-list-slider/block.json +++ b/src/blocks/_pro/post-list-slider/block.json @@ -164,6 +164,10 @@ "blockId": { "type": "string" }, + "stickyPosts": { + "type": "string", + "default": "include" + }, "className": { "type": "string", "default": "" diff --git a/src/blocks/_pro/post-list-slider/edit.js b/src/blocks/_pro/post-list-slider/edit.js index af4ea1aff..02b2a29f7 100644 --- a/src/blocks/_pro/post-list-slider/edit.js +++ b/src/blocks/_pro/post-list-slider/edit.js @@ -27,6 +27,7 @@ export default function PostListSliderEdit(props) { const postTypesProps = vk_block_post_type_params.post_type_option; const termsByTaxonomyName = vk_block_post_type_params.term_by_taxonomy_name; + const stickyPosts = attributes.stickyPosts; const { layout, @@ -129,6 +130,7 @@ export default function PostListSliderEdit(props) { setAttributes={setAttributes} postTypesProps={postTypesProps} termsByTaxonomyName={termsByTaxonomyName} + stickyPosts={stickyPosts} /> 'date', 'offset' => 0, 'pagedlock' => false, + 'stickyPosts' => 'include', 'selfIgnore' => false, 'loop' => true, 'effect' => 'slide', diff --git a/src/blocks/_pro/post-list/block.json b/src/blocks/_pro/post-list/block.json index 9c6a05fb2..c6c505d93 100644 --- a/src/blocks/_pro/post-list/block.json +++ b/src/blocks/_pro/post-list/block.json @@ -128,6 +128,10 @@ "type": "boolean", "default": false }, + "stickyPosts": { + "type": "string", + "default": "include" + }, "className": { "type": "string", "default": "" diff --git a/src/blocks/_pro/post-list/edit.js b/src/blocks/_pro/post-list/edit.js index 7451362b2..1a139d650 100644 --- a/src/blocks/_pro/post-list/edit.js +++ b/src/blocks/_pro/post-list/edit.js @@ -14,7 +14,7 @@ export default function PostListEdit(props) { const postTypesProps = vk_block_post_type_params.post_type_option; const termsByTaxonomyName = vk_block_post_type_params.term_by_taxonomy_name; - + const stickyPosts = attributes.stickyPosts; const blockProps = useBlockProps(); // リンクを無効にする関数 @@ -72,6 +72,7 @@ export default function PostListEdit(props) { setAttributes={setAttributes} postTypesProps={postTypesProps} termsByTaxonomyName={termsByTaxonomyName} + stickyPosts={stickyPosts} /> diff --git a/src/blocks/_pro/post-list/index.js b/src/blocks/_pro/post-list/index.js index 1706b2820..ba71c7a9d 100644 --- a/src/blocks/_pro/post-list/index.js +++ b/src/blocks/_pro/post-list/index.js @@ -41,6 +41,7 @@ export const settings = { taxQueryRelation: 'AND', order: 'DESC', orderby: 'date', + stickyPosts: 'include', }, }, edit, diff --git a/src/blocks/_pro/post-list/index.php b/src/blocks/_pro/post-list/index.php index 19c61d1ca..a332aa007 100644 --- a/src/blocks/_pro/post-list/index.php +++ b/src/blocks/_pro/post-list/index.php @@ -221,6 +221,10 @@ function vk_blocks_register_block_post_list() { 'type' => 'boolean', 'default' => false, ), + 'stickyPosts' => array( + 'type' => 'string', + 'default' => 'include', + ), 'className' => array( 'type' => 'string', 'default' => '', diff --git a/src/components/display-condition/index.js b/src/components/display-condition/index.js index 102b80e81..871fc31e2 100644 --- a/src/components/display-condition/index.js +++ b/src/components/display-condition/index.js @@ -32,6 +32,7 @@ export function DisplayCondition(props) { orderby, selfIgnore, pagedlock, + stickyPosts, } = attributes; // 以前の値を切り替え @@ -428,6 +429,33 @@ export function DisplayCondition(props) { onChange={(v) => setAttributes({ selfIgnore: v })} /> + + { + setAttributes({ stickyPosts: value }); + if (value === 'include') { + setAttributes({ stickyPosts: false }); + } + }} + help={__( + 'Sticky posts always appear first, regardless of their publish date.', + 'vk-blocks-pro' + )} + /> + ); } diff --git a/test/phpunit/pro/test-post-list-query.php b/test/phpunit/pro/test-post-list-query.php index 2f4d157ec..cc996c9e7 100644 --- a/test/phpunit/pro/test-post-list-query.php +++ b/test/phpunit/pro/test-post-list-query.php @@ -275,6 +275,24 @@ public function test_get_loop_query() { 'target_url' => home_url( '/event/page/2' ), ), ), + // Stickt Post 除外設定 + array( + 'attributes' => array( + 'isCheckedPostType' => '["event"]', + 'isCheckedTerms' => json_encode( + array( + $test_data['term_id_event_area_aichi'], + $test_data['term_id_event_cat_a'], + ) + ), + 'stickyPosts' => 'exclude' + ), + 'expected' => array( + $test_data['post_id_a_aichi'], + $test_data['post_id_b_aichi'], + $test_data['post_id_a_online'], + ), + ), ); $vk_blocks_post_list = new Vk_Blocks_PostList(); diff --git a/test/phpunit/pro/test-post-list.php b/test/phpunit/pro/test-post-list.php index 2aa5d1b0e..d99d59731 100644 --- a/test/phpunit/pro/test-post-list.php +++ b/test/phpunit/pro/test-post-list.php @@ -93,6 +93,7 @@ public function test_post_list() { 'order' => 'ASC', 'orderby' => 'title', 'offset' => 0.0, + 'stickyPosts' => 'include', 'selfIgnore' => true, 'vkb_hidden' => false, 'vkb_hidden_xxl' => false, @@ -307,6 +308,17 @@ public function test_get_loop_query() { ), 'expected' => array( 'Event post', 'Normal post' ), ), + 'スティッキーポストを除外' => array( + 'attributes' => array( + 'numberPosts' => 6.0, + 'isCheckedPostType' => '["post","event"]', + 'isCheckedTerms' => '[]', + 'order' => 'ASC', + 'orderby' => 'title', + 'stickyPosts' => 'exclude', + ), + 'expected' => array( 'Child-category post', 'Event post', 'Normal post' ), + ), 'カテゴリーの or 検索' => array( 'attributes' => array( 'numberPosts' => 6.0,