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

【2人目確認中】[ 投稿リスト / 投稿リストスライダー ] 先頭固定表示の投稿の設定を追加 #2420

Open
wants to merge 34 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3ce3d05
Add stickyPosts
Jan 24, 2025
6ce2d20
Fix: stickyPosts
Jan 24, 2025
7ee3b0c
Fix: stickyPosts
Jan 24, 2025
f00e5ee
Add stickyPosts
Jan 24, 2025
11ca6da
Add stickyPosts
Jan 24, 2025
a656037
Add stickyPosts
Jan 24, 2025
81968ad
Add initial setting
Jan 24, 2025
476d08b
Add stickyPosts for test
Jan 24, 2025
851fa4d
Fix:
Jan 24, 2025
02a8610
Fix: snake case
Jan 24, 2025
06b5c0d
Delete: commentout
Jan 24, 2025
3dca126
Add changelog
Jan 24, 2025
36d475f
Add new line
Jan 24, 2025
84b9485
Merge branch 'develop' into feature/post-list/sticky-posts
mtdkei Feb 5, 2025
9a35f91
Merge branch 'develop' into feature/post-list/sticky-posts
mtdkei Feb 5, 2025
4ca02ca
Fix: Sticky posts
Feb 6, 2025
21330b9
Fix: Lint
Feb 6, 2025
7b1e179
Fix:
Feb 6, 2025
7796cc0
Fix: Lint
Feb 6, 2025
ea554f8
Fix: unnessecary code
Feb 6, 2025
b8139d5
Fix: Lint
Feb 6, 2025
314e3a8
Fix: Exclude and Only mode
Feb 6, 2025
41fe3e2
Fix: Lint
Feb 6, 2025
86ca0da
Merge branch 'feature/post-list/sticky-posts' of https://github.com/v…
mthaichi Feb 6, 2025
fa2257a
Fix: case only
Feb 7, 2025
9f24a7f
Fix: Delete commentouut
Feb 7, 2025
8589da0
Fix: Delete commentouut
Feb 7, 2025
d5326e2
Fix: Delete commentout
Feb 7, 2025
facf894
Fix: lint
Feb 7, 2025
e415aec
Fix coding standard violation: Replace ?: with ? :
Feb 7, 2025
f5e4cfd
Fix: lint
Feb 7, 2025
209b259
Merge branch 'develop' into feature/post-list/sticky-posts
mtdkei Feb 18, 2025
e8ccb43
Merge branch 'develop' into feature/post-list/sticky-posts
mtdkei Feb 25, 2025
a8fd9c5
Merge branch 'develop' into feature/post-list/sticky-posts
mthaichi Feb 28, 2025
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
20 changes: 20 additions & 0 deletions inc/vk-blocks/view/class-vk-blocks-postlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions src/blocks/_pro/post-list-slider/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@
"blockId": {
"type": "string"
},
"stickyPosts": {
"type": "string",
"default": "include"
},
"className": {
"type": "string",
"default": ""
Expand Down
2 changes: 2 additions & 0 deletions src/blocks/_pro/post-list-slider/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -129,6 +130,7 @@ export default function PostListSliderEdit(props) {
setAttributes={setAttributes}
postTypesProps={postTypesProps}
termsByTaxonomyName={termsByTaxonomyName}
stickyPosts={stickyPosts}
/>
<PanelBody
title={__('Display type', 'vk-blocks-pro')}
Expand Down
1 change: 1 addition & 0 deletions src/blocks/_pro/post-list-slider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const settings = {
taxQueryRelation: 'AND',
order: 'DESC',
orderby: 'date',
stickyPosts: 'include',
},
},
edit,
Expand Down
1 change: 1 addition & 0 deletions src/blocks/_pro/post-list-slider/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ function vk_blocks_post_list_slider_render_callback( $attributes ) {
'orderby' => 'date',
'offset' => 0,
'pagedlock' => false,
'stickyPosts' => 'include',
'selfIgnore' => false,
'loop' => true,
'effect' => 'slide',
Expand Down
4 changes: 4 additions & 0 deletions src/blocks/_pro/post-list/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@
"type": "boolean",
"default": false
},
"stickyPosts": {
"type": "string",
"default": "include"
},
"className": {
"type": "string",
"default": ""
Expand Down
3 changes: 2 additions & 1 deletion src/blocks/_pro/post-list/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

// リンクを無効にする関数
Expand Down Expand Up @@ -72,6 +72,7 @@ export default function PostListEdit(props) {
setAttributes={setAttributes}
postTypesProps={postTypesProps}
termsByTaxonomyName={termsByTaxonomyName}
stickyPosts={stickyPosts}
/>
<ColumnLayoutControl {...props} />
<DisplayItemsControl {...props} />
Expand Down
1 change: 1 addition & 0 deletions src/blocks/_pro/post-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const settings = {
taxQueryRelation: 'AND',
order: 'DESC',
orderby: 'date',
stickyPosts: 'include',
},
},
edit,
Expand Down
4 changes: 4 additions & 0 deletions src/blocks/_pro/post-list/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '',
Expand Down
28 changes: 28 additions & 0 deletions src/components/display-condition/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function DisplayCondition(props) {
orderby,
selfIgnore,
pagedlock,
stickyPosts,
} = attributes;

// 以前の値を切り替え
Expand Down Expand Up @@ -428,6 +429,33 @@ export function DisplayCondition(props) {
onChange={(v) => setAttributes({ selfIgnore: v })}
/>
</BaseControl>
<BaseControl>
<SelectControl
label={__('Sticky Posts', 'vk-blocks-pro')}
value={stickyPosts}
options={[
{
label: __('Include', 'vk-blocks-pro'),
value: 'include',
},
{
label: __('Exclude', 'vk-blocks-pro'),
value: 'exclude',
},
{ label: __('Only', 'vk-blocks-pro'), value: 'only' },
]}
onChange={(value) => {
setAttributes({ stickyPosts: value });
if (value === 'include') {
setAttributes({ stickyPosts: false });
}
}}
help={__(
'Sticky posts always appear first, regardless of their publish date.',
'vk-blocks-pro'
)}
/>
</BaseControl>
</PanelBody>
);
}
18 changes: 18 additions & 0 deletions test/phpunit/pro/test-post-list-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
12 changes: 12 additions & 0 deletions test/phpunit/pro/test-post-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Loading