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

Issue with code formatting on the WP_Query docs page #838

Closed
rmorse opened this issue May 25, 2023 · 8 comments
Closed

Issue with code formatting on the WP_Query docs page #838

rmorse opened this issue May 25, 2023 · 8 comments
Assignees
Labels
code reference Issues for Code Reference portal of DevHub developer documentation (DevHub) Improvements or additions to developer documentation

Comments

@rmorse
Copy link

rmorse commented May 25, 2023

Issue Description

All the code examples are missing indentation.

URL of the Page with the Issue

https://developer.wordpress.org/reference/classes/wp_query/

Section of Page with the issue

Why is this a problem?

Makes it hard to read + understand

Suggested Fix

Add the tabbed indentation back in (and maybe figure out how it got lost - was it an automated process?)

@rmorse rmorse added the tracking issue Use to track a series of related issues. label May 25, 2023
@zzap
Copy link
Member

zzap commented May 25, 2023

Heads up @WordPress/docs-issues-coordinators, we have a new issue open. Time to use 'em labels.

@creative-andrew
Copy link

I will take care of this one if that is okay.

@creative-andrew
Copy link

creative-andrew commented Jun 8, 2023

Here is the list of suggested modifications:

Standard Loop:

  • Fixed indentation.
  • Escaped string for security.
  • Added internationalization.
<?php

// The Query.
$the_query = new WP_Query( $args );

// The Loop.
if ( $the_query->have_posts() ) {
	echo '<ul>';
	while ( $the_query->have_posts() ) {
		$the_query->the_post();
		echo '<li>' . esc_html( get_the_title() ) . '</li>';
	}
	echo '</ul>';
} else {
	esc_html_e( 'Sorry, no posts matched your criteria.' );
}
// Restore original Post Data.
wp_reset_postdata();

Standard Loop Alternate:

  • Fixed indentation.
  • Escaped string for security.
<?php
// the query.
$the_query = new WP_Query( $args ); ?>

<?php if ( $the_query->have_posts() ) : ?>
	<!-- pagination here -->

	<!-- the loop -->
	<?php
	while ( $the_query->have_posts() ) :
		$the_query->the_post();
		?>
		<h2><?php esc_html( the_title() ); ?></h2>
	<?php endwhile; ?>
	<!-- end of the loop -->

	<!-- pagination here -->

	<?php wp_reset_postdata(); ?>

<?php else : ?>
	<p><?php esc_html_e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

@zzap zzap added developer documentation (DevHub) Improvements or additions to developer documentation code reference Issues for Code Reference portal of DevHub and removed tracking issue Use to track a series of related issues. labels Jun 13, 2023
@github-actions
Copy link

Heads up @zzap - the "code reference" label was applied to this issue.

@zzap zzap self-assigned this Jun 13, 2023
@zzap zzap mentioned this issue Jun 13, 2023
16 tasks
@zzap
Copy link
Member

zzap commented Jun 14, 2023

Examples are fixed and props added in https://core.trac.wordpress.org/ticket/58537

Thank you @creative-andrew for working on this ❤️

@zzap zzap closed this as completed Jun 14, 2023
@audrasjb
Copy link

audrasjb commented Jun 14, 2023

Hello @creative-andrew there is an issue in the second example:
<h2><?php esc_html( the_title() ); ?></h2>
This doesn't work :)

Should be replaced with:
<h2><?php the_title(); ?></h2>
or:
<h2><?php echo esc_html( get_the_title() ); ?></h2>
The first option is used on bundled themes (example here), so I'd go with that one. The second one adds an extra escaping, which is not strictly needed in themes guidelines.

PS: @zzap I guess you opened a Core Trac ticket to try to props people? However since there is no associated commit, I don't think it will be taken into account anywhere 😬

@audrasjb audrasjb reopened this Jun 14, 2023
@zzap
Copy link
Member

zzap commented Jun 14, 2023

Fixed with <?php the_title( '<h2>', '</h2>' ); ?>. Thank you for spotting that @audrasjb 🙌

And yes, I wanted to give props to Andrew and was looking for a ticket without the actual commit. I guess I found out why there were none 🥲

@zzap zzap closed this as completed Jun 14, 2023
@audrasjb
Copy link

Thanks for the update!

@zzap zzap mentioned this issue Aug 8, 2023
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code reference Issues for Code Reference portal of DevHub developer documentation (DevHub) Improvements or additions to developer documentation
Projects
None yet
Development

No branches or pull requests

4 participants