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

Check for nextpage to display page links for paginated posts #37672

Conversation

alberto-marin
Copy link
Contributor

Hi,
The "core/nextpage" it's a child of "core/post-content" but within the post-content there's no reference to it.

After getting the value for $post_id we could see that the block core/nextpage exists by using something like this:

$blocks = parse_blocks( get_post($post_id)->post_content );
var_dump($blocks);

Screenshot 2021-12-30 at 20 04 01

What is missing here is the ability to detect this "child" block. After applying the filter to the_content we could check and call the function that displays page links:

	// Check for nextpage to display page links for paginated posts
	$nextpage = has_block('nextpage') ? wp_link_pages(['echo' => 0]) : false;
	if ( false !== $nextpage ) {
		$content = get_the_content() . $nextpage;
	}

Screenshot 2021-12-30 at 20 12 17

I have tested it with the official wordpress themes from twentytwentynine to twentytwentytwo, and it works well.

This fix is related to this issue: #29484

Note that get_the_content() doesn't need the null and false attributes because those are the function defaults.

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Dec 30, 2021
@github-actions
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @alberto-marin! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@Mamaduka
Copy link
Member

Mamaduka commented Jan 4, 2022

Thanks for contributing, @alberto-marin.

I'm wondering if this should be a separate block. @carolinan, @kjellr, what do you think?

@carolinan
Copy link
Contributor

@Mamaduka I did not understand; the page break is already a block.

From the issue:
#29484

I have confirmed that if I add a page break block to a theme that supports full site editing, the block shows correctly in the site editor and post editor, but not the front.

The page break block also does not work with traditional/PHP based themes that does not add wp_link_pages(). See https://developer.wordpress.org/reference/functions/wp_link_pages/

Looks like without wp_link_pages, <!‐‐nextpage‐‐> which is saved in https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/nextpage/save.js#L7 is not understood?

@carolinan
Copy link
Contributor

Don't we need to add this in a new .php file for nextpage?
https://github.com/WordPress/gutenberg/tree/trunk/packages/block-library/src/nextpage

@Mamaduka
Copy link
Member

Mamaduka commented Jan 4, 2022

@carolinan, sorry for the confusion.

I meant "Page Links" as a separate/new block. The block will give theme authors more flexibility in displaying these links + styling options.

@kjellr
Copy link
Contributor

kjellr commented Jan 4, 2022

I meant "Page Links" as a separate/new block. The block will give theme authors more flexibility in displaying these links + styling options.

I think eventually, we should just follow the lead of what we do for standard query pagination. In that case, there are three separate blocks:

  • Previous Page
  • Page Numbers
  • Next Page

@Mamaduka
Copy link
Member

Mamaduka commented Jan 4, 2022

@kjellr, this is slightly different from Query pagination blocks.

You have separate methods (get_next_posts_link, paginate_links, etc.) handling each part of the functionality for Query blocks. While for the post's pages, we have a single method that handles all the above. It is the reason I was suggesting one new block.

@kjellr
Copy link
Contributor

kjellr commented Jan 4, 2022

That sounds like a technical reason, not a UX reason though — I think there's value in making pagination consistent wherever it's available so users don't have to re-learn it every time.

For the near term though, I don't have a strong preference about whether that's a separate block or not. That seems like a decent idea, but as long as this is showing up again for block themes I think we're good for now.

@Mamaduka Mamaduka added [Block] Post Content Affects the Post Content Block [Type] Bug An existing feature does not function as intended labels Jan 6, 2022
Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

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

Changes look good. Thanks, @alberto-marin.

@Mamaduka Mamaduka merged commit 1e4e1e3 into WordPress:trunk Jan 8, 2022
@github-actions
Copy link

github-actions bot commented Jan 8, 2022

Congratulations on your first merged pull request, @alberto-marin! We'd like to credit you for your contribution in the post announcing the next WordPress release, but we can't find a WordPress.org profile associated with your GitHub account. When you have a moment, visit the following URL and click "link your GitHub account" under "GitHub Username" to link your accounts:

https://profiles.wordpress.org/me/profile/edit/

And if you don't have a WordPress.org account, you can create one on this page:

https://login.wordpress.org/register

Kudos!

@github-actions github-actions bot added this to the Gutenberg 12.4 milestone Jan 8, 2022
@Mamaduka
Copy link
Member

@noisysocks, I'm adding a backport label for this PR. It's a small change and adds missing behavior.

@Mamaduka Mamaduka added the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Jan 10, 2022
@alberto-marin alberto-marin deleted the fix/29484--page-break-block-full-site-editing branch January 10, 2022 14:32
@noisysocks noisysocks removed the Backport to WP 6.7 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Jan 10, 2022
noisysocks pushed a commit that referenced this pull request Jan 10, 2022
* Check for nextpage to display page links for paginated posts

* fix php styles

* Update packages/block-library/src/post-content/index.php

Co-authored-by: George Mamadashvili <georgemamadashvili@gmail.com>

* Update packages/block-library/src/post-content/index.php

Co-authored-by: George Mamadashvili <georgemamadashvili@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Post Content Affects the Post Content Block First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants