Skip to content

Commit

Permalink
Nav sidebar: exclude the latest posts page (#44379)
Browse files Browse the repository at this point in the history
  • Loading branch information
p-jackson authored Jul 23, 2020
1 parent 5012986 commit 60922eb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,20 @@ public function enqueue_script_and_style() {
plugins_url( 'dist/', __FILE__ )
);

$post_ids_to_exclude = array();

// Only exclude page_for_posts when a static page is being used as the front page, because
// page_for_posts can be a valid id even when showing a traditional blog page on front.
if ( 'page' === get_option( 'show_on_front' ) ) {
$post_ids_to_exclude[] = get_option( 'page_for_posts' );
}

wp_localize_script(
'wpcom-block-editor-nav-sidebar-script',
'wpcomBlockEditorNavSidebar',
array(
'homeUrl' => home_url(),
'homeUrl' => home_url(),
'postIdsToExclude' => $post_ids_to_exclude,
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { compose } from '@wordpress/compose';
/**
* Internal dependencies
*/
import { STORE_KEY, SITE_HOME_URL } from '../../constants';
import { STORE_KEY, SITE_HOME_URL, POST_IDS_TO_EXCLUDE } from '../../constants';
import CreatePage from '../create-page';
import NavItem from '../nav-item';
import { Post } from '../../types';
Expand Down Expand Up @@ -273,7 +273,7 @@ function useNavItems(): Post[] {
const items =
select( 'core' ).getEntityRecords( 'postType', currentPostType, {
_fields: 'id,status,title',
exclude: [ currentPostId ],
exclude: [ currentPostId, ...POST_IDS_TO_EXCLUDE ],
orderby: 'modified',
per_page: 10,
status: statusFilter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ declare global {
interface Window {
wpcomBlockEditorNavSidebar?: {
homeUrl: string;
postIdsToExclude: string[];
};
}
}

export const SITE_HOME_URL = window.wpcomBlockEditorNavSidebar?.homeUrl;
export const POST_IDS_TO_EXCLUDE = ( window.wpcomBlockEditorNavSidebar?.postIdsToExclude || [] )
.map( ( id ) => parseInt( id, 10 ) )
.filter( ( id ) => ! isNaN( id ) );

0 comments on commit 60922eb

Please sign in to comment.